开发者

Make Entity Framework object into generic class via extension class?

开发者 https://www.devze.com 2023-02-22 19:51 出处:网络
I have an EF object called PagePreference.The corresponding table contains three fields: UserName(PK, varchar(200), not null), PageName(PK, varchar(700), not null), and PageState(text, null).The PageS

I have an EF object called PagePreference. The corresponding table contains three fields: UserName(PK, varchar(200), not null), PageName(PK, varchar(700), not null), and PageState(text, null). The PageState field contains a serialized (开发者_开发问答json) object. I have another class file which extends this EF object via the 'partial' keyword. The idea is that on any given page, I can create an object to contain the page state and serialize it into the PageState field in the PagePreference object. Each page would have a different PageState object so they wouldn't be compatible with each other. Because of this, I would like the PagePreference object to use generics (e.g. PagePreference) so that when the object is loaded, it can deserialize the page state into the appropriate class ('T'). However, when I added the generic notation to the extended PagePreference object, VisualStudio considers it a while new object. Anyone know of a way to get this to work?


it's only natural that this happens since generic and non-generic classes aren't the same. There isn't a way, I'm afraid to do this directly, since the entities are autogenerated. what you can try to do, however, is use POCOs which you should be able to mold anyway you want.

After trying to test this myself, I found out that EntityFramework doesn't support generics. Even with POCOs. (maybe not yet ;) )

0

精彩评论

暂无评论...
验证码 换一张
取 消