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've got an entity (EntityA) with a 1-Many relationship (to EntityB). I'd like to expose a property on EntityA which has a single instance of EntityB - specifically the First, according to a sortorder. So I'd have a readonly property called EntityA.MostRecentEntityB. For example, BankAccount and TransactionRetrieval. 1 BankAccount has many TransactionRetrievals. Here are some more details about the use case... I'm going to keep adding more and more TransactionRetrievals to the BankAccount collection. I do want to be able to go back and use these but for a given BankAccount, 90% of the time I'm only interested in the most recent TransactionRetrieval. Ideally I'd have something like an EntityHolder<TransactionRetrieval> on BankAccount which eager loads just the most recent TransactionRetrieval. This is a situation I come across quite regularly, where for a transactional system I'm wanting to eager load just the most recent 'many' entity for a 1-many relationship. I originally toyed with the idea of duplicating some of the properties from EntityB into EntityA. ie BankAccount .MostRecentTransactionRetrievalStatus, BankAccount .MostRecentTransactionRetrievalErrorMessage, but this gets pretty tiresome and error-prone, especially when TransactionRetrievals can be updated (not only inserted). Overriding TransactionRetrieval property setters, etc. It seems it would be a lot cleaner to be able to just reference a BankAccount.MostRecentTransactionRetrieval. How would you recommend this be done? Do I have to go down the sproc load route or is there some LS way of handling this with eagerload/namedaggregate/entityholder whizzyness? *some time later*... Or, should i just create a 1-1 relationship and add another FK to the BankAccount table (BankAccount.MostRecentTransactionRetrievalId)? Hmm, that might be it. Thanks for listening. :) thanks justin |
|
|
*much wailing and gnashing of teeth later* ok, that certainly doesn't work - see below exception message. So - back to my original question - how would you recommend this be done? :| html, body { font-family:tahoma, sans-serif; } h2 { height:15px; font-size:80%; } h2 a { text-decoration: none; color: #393939; } h2 a:hover { text-decoration: underline; } .failed { background-color:#EFC0C0; color:#393939; margin:5px 0 0 0; padding:5px 5px 3px 5px; } .ok { background-color:#C0EFC0; color:#393939; margin:5px 0 0 0; padding:5px 5px 3px 5px; } .ignored { background-color:#EFEFC0; color:#393939; margin:5px 0 0 0; padding:5px 5px 3px 5px; } div.node { border:1px solid #DCE2E8; padding:5px 5px 3px 5px; } div.exception { background-color:#E3E9EF; white-space: pre; color:#393939; height:15px; border-bottom:2px solid #DCE2E8; font-family:monospace; font-size:80%; margin:0; padding:5px 5px 3px 5px; } div.failMessage { background-color:#EFC0C0; white-space: pre; color:#393939; height:15px; font-family:monospace; font-size:80%; margin:0; padding:3px 5px 3px 5px; } div.ignoreMessage { background-color:#EFEFC0; white-space: pre; color:#393939; height:15px; font-family:monospace; font-size:80%; margin:0; padding:3px 5px 3px 5px; } div.stacktrace { background-color:#F1F4F7; white-space: pre; overflow:auto; color:#8B0000; font-family:monospace; font-size:80%; margin:0 0 5px 0; padding:8px 5px 8px 5px; } div.output { white-space: pre; overflow:auto; font-family:monospace; font-size:80%; margin:0 0 5px 0; padding:8px 5px 8px 5px; } .hoverLinkEmuLink { text-decoration: underline; cursor: pointer; } .normalLinkEmuLink { } // should not throw an exception : FailedCircular associations are not supported by LightSpeed: [TransactionRetrieval.BankAccount and BankAccount.LastTransactionRetrieval]
Mindscape.LightSpeed.LightSpeedException: Circular associations are not supported by LightSpeed: [TransactionRetrieval.BankAccount and BankAccount.LastTransactionRetrieval]
|
|
|
this post (http://www.mindscape.co.nz/forums/Thread.aspx?PostID=11534) also looks as though it has the exact same problem... |
|
|
Certainly for now this isnt something we have a feature for - although this is an interesting idea, so we might have a think about this one after TechEd finishes up :) For now what I would suggest is that you have a property of the entity which holds the "latest value" which you can either manage manually or via a trigger from the collection change as a new entity is added. You can then expose a custom property which calls a UnitOfWork.FindById<TEntity>(yourIdProperty) to return the actually entity back (keeping in mind that this is fetched from the identity map after the first call so you wouldnt need to worry about holding the value yourself).
Jeremy |
|
|
ok, that mostly works. I do have a major problem though - in the order that the unit of work carries out its updates/inserts. Looks like the unit of work tries to update the (BankAccount) Entity before it has inserted the new TransactionRetrieval. So the FK constraint (BankAccount.LastTransactionRetrievalId) fails - because the TransactionRetrieval hasn't been inserted yet. I do recall someone else here having an issue recently with the order of unit of work updates/inserts. I'll see if he can give more details too. Have sent email with details - sql and BankAccount class... cheers justin |
|
|
and just for completeness - the actual sql exception (table names changed): The UPDATE statement conflicted with the FOREIGN KEY constraint "FK_BankAccount_LastTransactionRetrieval". The conflict occurred in database "BankFeeds", table "BankAccount.LastTransactionRetrieval", column 'Id'. |
|
|
btw, for the moment I'll go with the obvious workaround of removing the FK constraint. |
|