views:

384

answers:

2

I just started to play around with Linq to entities and ran into an issue I can't figure out. I know this doesn't tell everything but to make it easier to understand here is a screen shot of the culprit... alt text

I am getting this error:
Condition member 'RelatedResources.TypeID' with a condition other than 'IsNull=False' is mapped. Either remove the condition on RelatedResources.TypeID or remove it from the mapping.

The condition that exists is a TypeID field in the abstract entity RelatedResource that defines the type of RelatedResource(Book,Link,guide, ect...) TypeID is also a foreign key and is mapped in the association with the Resource Type entity. I think this is the problem but I don't know how or why I should change this.

Any ideas??? Thanks!!

A: 

Is RelatedResources.TypeID set to be not null (ie. 'Isnull=false') in the database and in the entityframework schema?

Not sure you can both have that field as a conditional and acts as a foreign key to another table.

And would you need to if you using the conditional inheritance to determine the type?

Hath
yes I should never have a null value for the typeID.
Mike
+2  A: 

That usually happens when you have TypeID as a condition and also use it as a property. It might be causing problems because you are using it to map the association with ResourceType AND using it as a condition for the inheritance.

NotDan
Thats what I'm thinking but I don't know a way around it.
Mike
Are you trying to use the ResourceType entity/table to determine the type of the RelatedResource? I.e. if ResourceType.Name == "Book" then the actual type of the RelatedResource is Book? If that's the case, your mixing inheritance with containment (which entity framework doesn't like, unfortunately). From an OOP point of view, the Name/Icon properties should actually be in the inherited classes (i.e. Book should define its own name and icon, not another type)
NotDan
Exactly... Good point. I'll play around with that for a little. Thanks.
Mike
After a good bit of experimenting I think the best way for me to handle this is abandon inheritance. I hate to do this but I can't see a way around it. If you have any ideas please let me know... what I would really like to do is combine the resourceType entity with the RelatedResource entity to solve everything including the oop design you mentionesd. But I don't know how :(
Mike