2

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 different base classes".

HBCondo
  • 895
  • 3
  • 10
  • 26

1 Answers1

1

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).

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • I don't know with Linq-to-SQL, but it definitely doesn't work with 4.0 of the entity frameowrk but only with the POCO classes that I create from scratch. I would like to add properties to the auto-generated entities at runtime b/c we are retrieving name-pair values that vary per tenant. – HBCondo Nov 29 '10 at 23:51
  • @user327066 - have you tried the POCO tools? http://blogs.msdn.com/b/adonet/archive/2010/01/25/walkthrough-poco-template-for-the-entity-framework.aspx – Marc Gravell Nov 30 '10 at 05:52