O'Reilly Forums: Trivially Simple Model Fails - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Trivially Simple Model Fails

#1 User is offline   Chris Arnold 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 07-July 09
  • Gender:Male
  • Location:UK

Posted 07 July 2009 - 08:51 AM

Hi Julie (et al),

Apologies for the long post!

I've been going through your book over the past few weeks in order to assess EF for my company. Unfortunately, it's not been an easy ride sad.gif. It seems that pretty much everything I try to do with the book examples fail. So, I created my own, trivially simple, database and entity model to test some inheritance with. This also failed to work. Having read much about EF v1's limitations I have also tried my same example on a Windows 7 VM running VS2010 and .Net 4 (Beta 1). Again, same results.

Attached is a VS2008 solution containing a SQL 2005 Database Project and a Class Library for the Entity Model.

All I am trying to do is use some TPH Inheritance to create a Client entity that extends the Person entity. Steps taken...

  1. Add an Entity to the Designer called Client with a Base type of Person.
  2. Add the Person table to the mappings collection of Client.
  3. Select the PersonTypeID as a condition and set its value to 1.

I then receive the following error:

Error 3032: Problem in Mapping Fragment starting at line 106: Condition member 'Person.PersonTypeID' with a condition other than 'IsNull=False' is mapped. Either remove the condition on Person.PersonTypeID or remove it from the mapping.
I think the problem might be that the item I want to use in the Condition forms part of the FK for the Person <-> PersonType relationship. In your example of extending Lodging to Resort you were able to 'massage' the conditional property (Resort bit) in the base class. This option doesn't seem to be available in my example.

What concerns me is that this is the first, most simple example I could think of for switching to an entity modelling layer and it doesn't seem to work unsure.gif. Any help or fixes would be very much appreciated.

Attached File(s)


0

#2 User is offline   Chris Arnold 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 07-July 09
  • Gender:Male
  • Location:UK

Posted 09 July 2009 - 10:28 PM

Looks like I'm off to use NHibernate then?

Seriously, I'm surprised at the lack of replies. Was my original post too garbled or am I missing something?

This post has been edited by Chris Arnold: 09 July 2009 - 10:29 PM

0

#3 User is offline   PeteSut 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 13
  • Joined: 05-June 09

Posted 10 July 2009 - 12:14 AM

QUOTE (Chris Arnold @ Jul 9 2009, 10:28 PM) <{POST_SNAPBACK}>
Looks like I'm off to use NHibernate then?

Seriously, I'm surprised at the lack of replies. Was my original post too garbled or am I missing something?

As this is a small forum for readers of the book I doubt it's actively monitored by many people unless they have specific issues. I expect Julie will be along to help you when she has a chance.

Regarding your problem though, you won't be able to set a conditional mapping on PersonTypeID if it acts as a foreign key to another table; as stated at the bottom of p.324 in the book a column can only have a single mapping in the model.
0

#4 User is offline   JulieLerman 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 334
  • Joined: 17-September 08

Posted 04 August 2009 - 01:26 PM

it looks like my notifications got flipped off again. Sorry for the lack of replies.

I'm sorry taht you have been having so much trouble. What seems trivial to you is unfortunatley out of the scope of EF's rules.

What Pete says is correct - that you can't map one field twice. The personTypeID is involved in the association mapping to person type. So you can't use it for Condition. Or if you use it for Condition then you can't use it for teh association and will therefore lose your navigation to PersonType.

I've been trying to think of how you can have your cake and eat it too.

If you had a client type inherited from person, then CLIENT won't need a navigation back to persontype because you already know the type - it's a client. However, you will lose the navigation property (by using the persontypeid in the condition) and won't be able to identify the type for the other people.

I can't see past this but I'm sure there is some clever work around. I would recommend trying the MSDN forums since lots of EF team members hang out there.

http://social.msdn.microsoft.com/forums/en...mework/threads/

Now off to see what other questions I have missed in the past month. :-(

julie




0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users