datacontext

Aug 16, 2008 at 10:41 AM

Hi I'm trying to migrate your site to Preview 4 of MVC, but I encounter some problems

I add to change the call and the view to user controls (update)

 

 

<div id="updates">

 

 

 

 

<% Html.RenderAction<InOutComponentController>(c => c.Updates());%>

<%

-- <%= Html.RenderUserControl("~/Views/InOut/Updates.ascx",ViewData["Updates"]) %>--%>

 

 

</div>

 

 

 

-----------------------------------------------------
Controller code i the same
-----------------------------------------------------

but when it's load, I have a DataContext has expired on


<%

= Html.ActionLink(

 

update.User.Profile.FirstName ==

null ||

 

update.User.Profile.FirstName ==

string.Empty ?

 

update.User.Aspnet_User.UserName :

update.User.Profile.FirstName +

" "

 

 

 

 

+ update.User.Profile.LastName,

 

"UserDetail", "Updates", new { id = update.Aspnet_Membership.UserId }) %>:

User.Entity is disposed (what is logical), How do you manage to keep it alive ?

 

Coordinator
Aug 16, 2008 at 8:51 PM
The problem is likely due to the fact that I am employing a using(datacontext) { } strategy on the controller methods.

I have had other occasions where I found that I could not do this because it would dispose of the object before the view was done with it, although typically if I am rendering the view in the using() { } then it isn't an issue.  In those instances I made a deconstructor that disposes of the datacontext.

You don't even have to do either explicitly, I just find myself typically doing this from habit.

I'm not in a position to review the source at the moment, but when I am home later I will take a look and see if this is in fact the case (I'm about 99% sure).

I plan on migrating this to preview 4 soon, although I plan on doing some more work on the membership code since preview 4 has some built in attributes and no longer requires the MvcMembership library.

I will check back later, let me know if this helps.

Paul
Aug 19, 2008 at 6:15 AM
It's working with your last code (inoutdotnet-14452) in preview 4!
Where do you use "Quote" ?
cordially
Davy
----- Original Message -----
From: [email removed]
To: [email removed]
Sent: Saturday, August 16, 2008 11:28 PM
Subject: Re: datacontext [inoutdotnet:33646]

From: paulrday

The problem is likely due to the fact that I am employing a using(datacontext) { } strategy on the controller methods.

I have had other occasions where I found that I could not do this because it would dispose of the object before the view was done with it, although typically if I am rendering the view in the using() { } then it isn't an issue. In those instances I made a deconstructor that disposes of the datacontext.

You don't even have to do either explicitly, I just find myself typically doing this from habit.

I'm not in a position to review the source at the moment, but when I am home later I will take a look and see if this is in fact the case (I'm about 99% sure).

I plan on migrating this to preview 4 soon, although I plan on doing some more work on the membership code since preview 4 has some built in attributes and no longer requires the MvcMembership library.

I will check back later, let me know if this helps.

Paul
Coordinator
Aug 19, 2008 at 1:51 PM
Great, glad to hear it!

I haven't implemented Quote yet, the idea is that on the updates page random quotes will be shown (I don't know where I am going to put them yet).

Users will have the ability to submit quotes and administrators will be able to add their own quotes, approve user quotes, or delete quotes.