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
|
Hi! I have for example the entities:
Now I would like to ask the question which I would write in SQL something like: SELECT *
That is, give me a list of all the toys the kid with Id 1 currently does not have. How do I express this? I have searched the samples and documentation, but I haven't found anything, but as I said, I'm new to this. Björn |
|
|
Hi Björn You can write this LightSpeed like so: IList<Toy> toys = Repository.Find<Toy>( !(Entity.Attribute("KidToy.KidId") == 1) ); Cheers, Andrew. |
|
|
Thank you Andrew! Unfortunately this does not work. I get the following error: Mindscape.LightSpeed.LightSpeedException: Path component [KidToys] not found in type [Toy]. What am I missing? Best regards Björn Andersson |
|
|
Your intersection table is probably called KidToy not KidToys Cheers, Andrew. |
|
|
Sorry. The tables are not really named "Toy", "Kid" etc. I have obscured the real table names. Yes, it should be KidToy, but this was just a typo when I translated the error message. The problem still persists. Thanks! Björn |
|
|
My test environment seems not to have compiled my test code correctly. The proper error message is Mindscape.LightSpeed.LightSpeedException: Could not determine the reverse association of [Toy.KidList (IList<Kid>)] This sounds to me as if I have configured something wrong? /Björn
|
|
|
Make sure you have all your associations declared correctly. Take a look at the help file and samples for details on how to declare associations. Cheers, Andrew. |
|
|
OK. I'm lost. I have looked att the samples and cannot figure this out. I tried to modify the sample and added another test: i.e. Give me all products which does not have a corresponding OrderDetail for the Order with Id 1. This should be basically what I need to do. Doing this gives me the same set of errors as I get when I try to implement the corresponding query on my tables. Could you tell me how to set up the relations for the sample in order to make this query run, that way I think my problem will also be solved!
Thanks for any help! /Björn |
|
|
Hi I have now worked with Björn on this example and I've got it working correctly as it should. However, I am a little bith puzzled by you answer above as well as a naming convention usability issue for the ORM usage in this case. To continue on Björns example above, he basically began by listed the names the tables and their corresponding entity classes. However, in the Kid entity class, we have a naming convention like this for the property: public EntityCollection<Kid_Toy> Kid_ToyList .... Since it actually is a list, the naming convention does seem ok I think in our case. However, in order for the query to work we have to write: IList<Toy> toys = Repository.Find<Toy>( !(Entity.Attribute("Kid_ToyList.KidId") == 1) ); which produces the correct SQL as desired which is great. However, in your previous answer, it seemed like it was the actual name of the intersection table that should be used instead of the property of the corresponding entity class property in Toy class. Or did I misunderstand you? In this case, I guess Entity.Attribute always corresponds to entity class properties rather than the equivalent names in the database? As for the usability aspect of this, the notion Kid_ToyList.KidId seems a bit weird since Kid_ToyList is a List and does not have a property KidId. Do you have any thoughts here? best regards, Tobias
|
|
|
Hi Tobias, Queries are always specified in terms of model attributes and associations. In the case of Kid_ToyList.KidId we're traversing a path from our target object Toy down through the Kid_ToyList association to a target attribute: KidId (on the Kid_Toy model). It's LightSpeed's job to figure out how to map this to the underlying database schema. I wouldn't personally name an association Kid_ToyList but simply KidToys. Cheers, Andrew.
|
|
|
Ok,tanks. That'll as an answer for me. As far as table / domain name labeling , that is just a naming convention. I was more puzzled over the plural collection to singular notation in the query path. But it's no big deal for me. Thanks.
Hmm. Don't seem to be possible to mark questions as solved anymore in the forum? |
|