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'm trying to add 1 new item to the database. I have a repository with a UnitOfworkScope. It always saves 2 records. One with data in it and one filled with nulls. My add method looks like this:
public void Add(TEntity item)
Also tried:
public void Add(TEntity item)
Both produce the same result. |
|
|
It looks like your Add method (or our Add method) is being called twice with different entity instances, one unpopulated and one populated. Put a breakpoint on the Add method and examine item in the debugger. If item is full of nulls, this is the offending call -- the call stack should show you where it's coming from. If that doesn't help, can you provide a small but complete project that reproduces the error? You can attach a zip file via the Options tab. Thanks! |
|
|
Thanks for the reply. Unfortunately I don't think its that simple. Add is only being called once. I think perhaps it has to do with UnitOfWork scoping. I can't wrap up a small project right now as the instancing is quite involved (IOC container, UnitOfWorkScope, etc.). I'll see if I can investigate a little further and perhaps isolate the code in a smaller project. It might help if there were some more comprehensive MVC examples to download |
|
|
Okay, we'll wait for more info. In the meantime, for a MVC sample, check out the Film Festival sample included in the download -- we'd welcome any feedback on what you'd like to see in a "more comprehensive" sample. Thanks! |
|
|
OK, this definitely is a uow scoping issue. I am used to using POCOs, so I have 2 Actions:
[AcceptVerbs(HttpVerbs.Get)] The first action is the "Get" and it creates an instance of Workout and initializes some values. Then the view is displayed and the "post" action used binding to create a new instance of the item. Then the item is added to the repository where SaveChanges() is called. However _both_ items are saved even though they are created in 2 different requests.
My IOC container is instantiating PerRequestUnitOfWorkScope and that is handed off to the repository. I really expect in stateless environment that the item I create in the first request should be discarded. I even tried to call "detach"
I had considered building a pure value object or dto for using in my view and ultimately this probably will be the solution I go with, but using the Lightspeed entities in my view should work and I'm confused as to how the PerRequestUnitOfWorkScope is working (or not working as the case may be). Regards,
Trevor |
|
|
Hi Trevor, Indeed, it sounds like you are carrying around the same UnitOfWork between requests. Are you able to provide some details or an example of how you are using the PerRequestUnitOfWorkScope with your IOC and Repository classes? The PerRequestUnitOfWorkScope works by fetching the current UnitOfWork from the HttpContext.Current.Items collection, so each call to .Current will return whatever is stored there (or create a new one if none is found).
Jeremy |
|