开发者

Is it possible to dynamically add properties to an entity object?

is it possible to add properties at run-time to a class that was generated by the entity framework? I am successful in doing so with POCO classes that inherit from DynamicObject but when I try to do the same thing with my entity classes, I receive the error "Partial declarations of [class name] must not specify dif开发者_运维百科ferent base classes".


I'm actually pretty surprised that works with L2S; DynamicObject is a curious beast, after all. You could try ensuring you are using the EF 4 POCO support, rather than the 3.5SP1-style common-base-class approach, but to be honest I'm not sure this is the way to go... database objects shouldn't really have dynamic properties, IMO.

Your intent isn't clear, but if this is for data-binding purposes, you might want to look at custom object models, via ICustomTypeDescriptor or TypeDescriptionProvider. This is an older technology for seeming to extend objects at runtime (without needing dynamic).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜