O'Reilly Forums: 2Nd Edition, Pg 393, Section Titled "choosing To Turn A Base Class Into An Abstract Class". - O'Reilly Forums

Jump to content

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

2Nd Edition, Pg 393, Section Titled "choosing To Turn A Base Class Into An Abstract Class". Can't turn base class Lodging into an abstract class

#1 User is offline   JanisL 

  • New Member
  • Pip
  • Group: Members
  • Posts: 6
  • Joined: 17-November 11

Posted 23 November 2011 - 10:02 AM

hi, I'm using example "EDMX after Chapter 14 - 16 Customizations", which I've downloaded from your website:

Question is about Table Per Hierarchy Inheritance chapter. On page 393 it is written that it is possible to make base entity Lodging abstract. But when I do turn Lodging entity into abstract type, I receive:

Error 3023: Problem in mapping fragments starting at line 1393:Column Lodging.LodgingName in table Lodging must be mapped: It has no default value and is not nullable.

If I then set a default value ( in SSDL section ) for LodingName column, then next time I try to build the project I get same error for Lodging.ContactID:

Error 3023: Problem in mapping fragments starting at line 1393:Column Lodging.ContactID in table Lodging must be mapped: It has no default value and is not nullable.

But the thing is that both LodgingName and ContactID properties are mapped to appropriate table columns, so error makes no sense. So why do I get this error and why do I get it only if I make Lodging abstract?

thank you
0

#2 User is offline   JulieLerman 

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

Posted 05 December 2011 - 11:58 AM

ahhhh figured it out. Somehow the nonresort entity is missing from that model! When the lodging is abstract and we only have a type representing SOME of the lodgings (resorts), EF sees that since you can never instantiate a lodging, you have no way of representing the rows that don't meet the resort condition.

The ability to turn lodging into abstract was dependent on the previous section's instructions to add in the nonresort type. When I added the nonresort derived type back into the model and had its condition be resort=0, then the project built successfully.

I'll get a new copy of the model online at my earliest convenience but hopefully this answers the question.
0

#3 User is offline   JanisL 

  • New Member
  • Pip
  • Group: Members
  • Posts: 6
  • Joined: 17-November 11

Posted 05 December 2011 - 01:24 PM

View PostJulieLerman, on 05 December 2011 - 11:58 AM, said:

When the lodging is abstract and we only have a type representing SOME of the lodgings (resorts), EF sees that since you can never instantiate a lodging, you have no way of representing the rows that don't meet the resort condition.


EF doesn't complain when on page 371 ( TPT with Abstract Types ) we turn Contact into an abstract type and as such contacts that are not customer don't have an instantiated type to map to.

So why does EF complain if non-resort lodgings ( thus rows that don't meet the resort condition ) don't have an instantiated type to map to?


thank you
0

#4 User is offline   JulieLerman 

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

Posted 05 December 2011 - 01:26 PM

possibly because one is a TPH and the other is a TPT
0

#5 User is offline   JanisL 

  • New Member
  • Pip
  • Group: Members
  • Posts: 6
  • Joined: 17-November 11

Posted 05 December 2011 - 01:59 PM

View PostJulieLerman, on 05 December 2011 - 01:26 PM, said:

possibly because one is a TPH and the other is a TPT


I figured that much. But if you'd have to guess, why do you think EF complains with TPH, while it doesn't complain with TPT?
0

#6 User is offline   JulieLerman 

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

Posted 06 December 2011 - 01:57 PM

TPH & TPT have different concerns about nullability. See if this post helps explain it. I don't think I could do so as well:

http://blogs.msdn.co...e-strategy.aspx
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