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, Ivan, the other thread was quite long and started a new thread with a slightly different objective. One-way association to a base class works, and many thanks to you. (BTW, I read a blog post about it. Does the Designer now updates DB correctly?) And while waiting for two-way association support, I thought of doing it manually. Right now, I have to make assoication to leaf class that requires two-way association. Looking at autogenerated source code, there is a couple of lines of code to make it two-way association, like following..
[ReverseAssociation("Conversation")] private readonly EntityCollection<Npc> _npcs = new EntityCollection<Npc>(); [System.Diagnostics.DebuggerNonUserCode] public EntityCollection<Npc> Npcs { get { return Get(_npcs); } } So I thought I could make a onw-way association to the base class and add the code above to the partial class. It's little bit of extra coding but not a bad idea. I tried it but the collection doesn't hold any objects. Do you have an idea why it's not working? To me, two-way association to base class as well as one-way association is quite important. And I'll be extreamly happy to find a way to make above workaround to work. Thanks a lot! -chris |
|
|
With a normal association, that's exactly what you'd do. But you've specified the other side of this association as a one-way association. That tells LightSpeed not to consider it when trying to figure out the foreign key for the collection, and I'd guess think this is why the collection doesn't get populated. The solution is to use a query, e.g. public IEnumerable<Npc> Npcs { |
|
|
I was going to use the query first but I was worried about performance. I expect to have tens of thousands of entities later. Is the query cached? If so, would it smart enought to know to invalidate the cache when the Enitty is added/removed? Thanks. -chris |
|
|
The query isn't cached, though you can compile it for extra speed, and of course you can always cache the results of the query in a collection. That's pretty much what LightSpeed does internally, except we also have some additional plumbing to update the collection even if you change associations via FK instead of Add/Remove. |
|
|
I'm not certain if I can manage the cache properly myself. I guess I'll just query it each time until two-way association is supported later. Thanks -ck |
|