Is there any particular reason why you should query using discriminator value instead of using the base class type directly?
var companies = session.Query<Company>().ToList(); var baseClasses = session.Query<BaseClass>().ToList(); would be doing just fine. In my case, it would generate this kind of query: select baseClass0_.Id as Id5_, baseClass0_.Version as Version5_, ... from BaseClass baseClass0_ where baseClass0_.ClassType in (6, 3) where 6 and 3 are the discriminator values I set for the derived classes. On Wed, Jan 9, 2013 at 5:54 AM, James Klett <[email protected]> wrote: > Ok, but, can you tell me what the SQL generated is when querying for all > Companies? Because if it is WHERE discriminator = -1" then we have a > problem > > thanks > > JAMES > > On Tuesday, January 8, 2013 12:58:48 PM UTC-6, Maximilian Haru Raditya > wrote: > >> In my case, for the mapping of the base class, in your case Company, I >> set the discriminator value -1, as I'm using enumeration. "-1" implies an >> invalid value. >> So, I think you can set it to whatever you want. >> >> >> >> On Wed, Jan 9, 2013 at 12:39 AM, James Klett <[email protected]> wrote: >> >>> Yes, I am mapping to a single table. I do have a discriminator. >>> >>> Maybe I didn't explain it right in my original post. I have Company, >>> Customer, and Vendor. Company is abstract. the two sub classes have >>> discriminator values "Customer" and "Vendor".. Company does not have a >>> value for the discriminator because it will never be created. Only Customer >>> and Vendors will. The custom tool in VS2012, is telling my I need a value >>> for the discriminator in the Company class. So, I am not sure what to do. >>> >>> Let me know what more info I can provide >>> >>> thanks >>> >>> JAMES >>> >>> >>> On Monday, January 7, 2013 1:36:45 PM UTC-6, fknebels wrote: >>> >>>> So are you mapping to a single table in your db or are you mapping to 2 >>>> separate tables. The use of a discriminator says a single table so while >>>> you abstract Customer class won't have a Property name Discriminator, you >>>> still have to map a discriminator column on your map. >>>> >>>> See this post on inheritance in NHibernate >>>> >>>> http://notherdev.blogspot.com/****2012/01/mapping-by-code-**inheri** >>>> tance.html<http://notherdev.blogspot.com/2012/01/mapping-by-code-inheritance.html> >>>> >>>> >>>> On Monday, January 7, 2013, James Klett wrote: >>>> >>>>> New first time to NHibernate, used another tool for years though. >>>>> Working with already existing db design, that works with the other tool, >>>>> getting this error with NHibernate - DevArt EntityDesigner >>>>> >>>>> Custom tool error: Invalid inheritance 'Company_Customer'. Base Class >>>>> Discriminator Value is not specified.. >>>>> Single Table Inheritance: >>>>> >>>>> I have an abstract Company base class, and an inherited concrete >>>>> Customer and Vendor Classes. >>>>> >>>>> the discriminator is string "Customer", "Vendor" and I have no >>>>> discriminator on Company because it is abstract and should never be >>>>> created, and therefore there are only Vendors or Customers. >>>>> >>>>> Our current ORM, when querying Companies, will generate >>>>> WHERE discriminator = "Customer" or discriminator = "Vendor" >>>>> >>>>> So, how do I fix this error? If I put one in just to get rid of the >>>>> error e.g. "Company", then the generated SQL on a query for Companies >>>>> would >>>>> not be as shown above would it? it would be WHERE discriminator = >>>>> "Company" which will always return 0 zero results . >>>>> >>>>> How do I resolve this? >>>>> Thanks in advance >>>>> >>>>> JAMES >>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "nhusers" group. >>>>> To view this discussion on the web visit https://groups.google.com/d/* >>>>> *ms**g/nhusers/-/BeyLz8t2mVAJ<https://groups.google.com/d/msg/nhusers/-/BeyLz8t2mVAJ> >>>>> . >>>>> To post to this group, send email to [email protected]. >>>>> To unsubscribe from this group, send email to nhusers+unsubscribe@** >>>>> googlegrou**ps.com. >>>>> For more options, visit this group at http://groups.google.com/**group >>>>> **/nhusers?hl=en <http://groups.google.com/group/nhusers?hl=en>. >>>>> >>>> -- >>> You received this message because you are subscribed to the Google >>> Groups "nhusers" group. >>> To view this discussion on the web visit https://groups.google.com/d/** >>> msg/nhusers/-/Yt1H-H3DDgkJ<https://groups.google.com/d/msg/nhusers/-/Yt1H-H3DDgkJ> >>> . >>> >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to nhusers+u...@** >>> googlegroups.com. >>> >>> For more options, visit this group at http://groups.google.com/** >>> group/nhusers?hl=en <http://groups.google.com/group/nhusers?hl=en>. >>> >> >> >> >> -- >> Regards, >> >> Maximilian Haru Raditya >> > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/nhusers/-/apMWLFZUJO4J. > > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > -- Regards, Maximilian Haru Raditya -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
