locked
Derived classes in EF RRS feed

  • Question

  • I have an EDM what was created from a database, I have tables in the DB called Attribute and another called AttributeGroup.  There is a key in each table called GroupID that relates the two tables.  All of this is fine in the EDM, but I wanted to create an Entity object that is derived from the Attribute table with a condition set to a given group.

     

    So for instance the Amenity attribute is GroupID 1.  I want to create an Amenity entity that is derived from Attribute and set the condition to be “When GroupID = 1”

     

    Visual Studio wants me to map the GroupID from the Attribute table to a GroupID in my Derived class, first of all I don’t want a GroupID field in my Amenities table as it SHOULD be getting that from the Attribute superclass, shouldn’t it?  BUT if I go ahead and add the GroupID field and them map it I get their error:

     

    Error 3032: Problem in Mapping Fragment starting at line 2460: Condition member 'Attribute.GroupID' with a condition other than 'IsNull=False' is mapped. Either remove the condition on Attribute.GroupID or remove it from the mapping.

     

    Maybe I’m going about this totally the wrong way, can any one help?  More than just explaning away (if you can) the above error, how do I create this non DB table Entity class that is Derived from the Attribute class that is mapped to a DB table?

     

    A image of the part of the model is:

    http://app.onlinephotofiler.com/images/A_8/6/5/3/23568/EDM_7aace.JPG

    Friday, October 31, 2008 6:47 PM

Answers

  • Since the GroupID column in Attribute table is being used in the Association that connects Attribute and AttributeGroup entities, it can not be used in a condition too.

    You would have to use either DefiningQuery element is SSDL or QueryView element in MSL to get around the problem. But you would have to manipulate the XML directly for this and this will also make your mappings read only and you would have to use SProcs for doing the CUD operations.

     

    Docs for QueryView element in MSL : http://msdn.microsoft.com/en-us/library/cc716798.aspx

    Docs for DefiningQuery element in SSDL : http://msdn.microsoft.com/en-us/library/bb738450.aspx

     

    Thanks

    Srikanth

    Friday, October 31, 2008 9:25 PM