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 must be missing something amazingly basic here but I'm not sure what. I have a simple model of Orders and LineItems. An Order can have multiple LineItems; each LineItem belongs to one Order. My implementation of Order and LineItem looks like the Customers/Orders sample as far as I can tell. I create a sample Order with a LineItem as follows: Order order = new Order(); This correctly puts one Order and one LineItem into the database. I then query as follows: IList<Order> orders = Repository.Find<Order>(); This reports *two* LineItems against the newly created Order. If I restart the test harness then the query correctly reports only one LineItem for the Order. I've looked at the documentation and samples but didn't see much information around 1-to-many, so I can't figure out what I'm doing wrong. Can you point me in the right direction? (By the way, is this the right forum for questions like this or would you prefer to be emailed directly?) |
|
|
Hi Ivan, You don't need to explicitly add the LineItem to the Repository as it will be processed automatically as part of the Order. Even so, it should never appear twice so I'll investigate and fix that. Also, the SaveChanges method flushes pending changes to the database but does not complete the current unit of work. What this means is that when you requery your objects you will get back the same instances because they will be served from the current unit of work's identity map (level 1 cache.) Use Repository.CompleteUnitOfWork() if you want to start a new unit of work. This is the correct forum; thanks again for the feedback. Cheers, Andrew. |
|
|
Thanks Andrew. Adding Repository.CompleteUnitOfWork() seems to fix the problem. |
|