This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I made a simple entity that inherits from another entity using the ClassTableInheritance, similar to the example below: http://www.mindscape.co.nz/blog/index.php/2010/04/27/class-table-inheritance-in-lightspeed/ When querying the classes to get the data, I get this error: Query Error: Could not find field [PlayerId] on model [Footballer] I tried adding the PlayerType on each of the derived classes (tables), but I get a different error stating that the Footballer class doesn't exist. Any idea what's happening? Any help would be really great. Thanks!! |
|
|
It looks like you've specified PlayerId as the discriminator, rather than PlayerType. Try changing the discriminator attribute to PlayerType on each of the inheritance arrows. (And remove the PlayerType property from the derived classes -- it only needs to be on the base class.) |
|
|
Thanks for the quick reply - Sorry, I did mean PlayerType (I was changing the error message to be inline with the example shown by the link). If the derived classes don't have the discriminator column, it throws that error as mentioned. Just further info, once I've added the column and got that other error [SQLException: Invalid object name 'Athlete'], I noticed that the generated SQL is not appending the right schema to the derived class's tablename, eventhough the schema has been specified in the property list. *note: athlete is equivalent to FootBaller in the linked in example. |
|
|
Derived classes do not need their own copies of the discriminator field, and in fact it will cause compiler warnings (shadowing) and I suspect runtime errors if it's there. The discriminator property should be present *only* on the base class. I'm puzzled as to why that's giving you an error, but I'll need some more info to figure it out: any chance you could post your model and your query? (You can attach a file via the Options tab.) Thanks! |
|
|
Here's the model. Query is : Repository.Find<Athlete>().Where(a=?a.FirstName == "a");
|
|
|
You need a PersonTypeId property on the Person class (that is, the base class, not the derived classes). |
|
|
Sorry, my bad. Because it's a foreign key, it didn't show on the list and I thought that it would still be available as it exists in the table in the database and I had updated it from source. Sorry for wasting your time. I am getting another error now now saying "Invalid object name 'Athlete'". The sql generated on the output window is as follow. Note how it's not putting the Community schema for Athlete and it's using Athlete.Firstname instead of Person.Firstname. Is this because of user error again? Thanks
|
|
|
Ah, I see. As you've seen, we always exclude foreign keys from being imported as properties; but (confusingly in this case) we don't generate them unless you drag the associated table on, so that the association appears. So in your case if you had dragged PersonType onto the diagram, then the PersonTypeId would have been automatically supplied for you (like CountryId was); but because there was no PersonType association, we didn't do so. Sorry for the confusion. I've reproduced the bugs you've identified in the generated SQL, and committed fixes for them. These fixes will be included in the next nightly build (16 June) which will be available from about 1500 GMT from http://www.mindscape.co.nz/products/lightspeed/nightlybuilds.aspx (Express edition; from the store for Professional). Please let us know if you still see these problems after upgrading, and thanks for taking the time to report them! |
|
|
It's working now - thanks for the quick response. |
|
|
Hi, Perhaps I spoke too soon - I seem to have the same issue when I am doing a query like this (Note that Scholarship is linked to Athlete which is the derived class of Person) : Repository.Find<Scholarship>().Where(s => (s.Person.FirstName.ToLower() == firstName.ToLower())); The generated sql is as below, note that it thinks FirstName belongs to Athlete when it is part of Person. SELECT Thanks! |
|
|
I can't reproduce this with the current code. I know Jeremy has been making some fixes in this area but not all of them made it into the latest nightly. Could you try this again with the 26 June nightly (which will be available from about 1500 GMT) and see if that fixes the problem? If not, let us know and I'll see if I can figure out what I'm doing differently from you. |
|
|
I just installed the latest nightly build and the problem is still occurring. If you could take another look, that'd be great. Thanks. |
|
|
Aha, got it. It appears to be an issue with the way we handle the LINQ query. You can therefore work around the problem by writing your query with the core API: UnitOfWork.Find<Scholarship>(Entity.Attribute("Person.FirstName").Lower() == firstName.ToLower()); We'll let you know when we have a fix for the LINQ side. |
|
|
I've committed a fix for the LINQ issue which will be in the 29 June nightly build. Please let us know if you still run into problems. |
|