|
|
Rank: Apprentice Coder Groups: Member
Joined: 5/25/2010 Posts: 37 Points: 111 Location: italia
|
Hi at all, i have a problem when i try to deserialized an object that came from Entity Framework v4.
I receive this error from JIT: {Cannot evaluate expression because the current thread is in a stack overflow state.}
The query is very simple:
var q_user = (from item in this.myContainer.userSet where item.Id == 13 select item);
return q_user.Single();
The error happened if i try to call the Method from Console of Weborb. Insted, if i try to embed the Assembly (that contain the code) in a ASP.NET page, it run fine: so i think that the difference is that in the first case WEBORB try to deserialize the object.
Embed the Dll in the Asp.Net and call directly don't require weborb and work fine.
Any Help?
darez
|
|
 Rank: Administration Groups: Administration
Joined: 8/21/2006 Posts: 1,607 Points: 4,082 Location: Frisco, TX
|
Hi Darez, I entered a ticket into our JIRA: http://bugs.themidnightcoders.com/browse/WONET-124We will look into it and I will let you know the status. Mark
Mark Piller Midnight Coders, Inc. twitter: midnightcoderblog: blog.themidnightcoders.comwebsite: www.themidnightcoders.com
|
|
Rank: Apprentice Coder Groups: Member
Joined: 5/25/2010 Posts: 37 Points: 111 Location: italia
|
I think that i have resolved. If I detach the Entity, it work fine. myContainer.detach(myEntity); return myEntity; It work fine. With Web Services (asmx), dotnet work fine without detach the Entity (Automatically detach the entity?). Darez
|
|
Rank: Newbie Coder Groups: Member
Joined: 6/23/2010 Posts: 3 Points: -88 Location: Oldsmar, FL
|
darez wrote:Hi at all, i have a problem when i try to deserialized an object that came from Entity Framework v4.
I receive this error from JIT: {Cannot evaluate expression because the current thread is in a stack overflow state.}
The query is very simple:
var q_user = (from item in this.myContainer.userSet where item.Id == 13 select item);
return q_user.Single();
Oh man, I spent all day trying to solve this one. I have good news and bad news. Bad news first - I wasn't able to find a solution I thought would work for us using the Entity Framework (standard) template. I noticed one approach of detaching from the container - that didn't work for me. The good news, and depending on your project requirements maybe this isn't good news, but when I switched over to the POCO template for Entity Framework this problem went away. And to my surprise, I didn't have to change a single line of code - it just worked. There are some good arguments for using the POCO template as well (not all the extra baggage of the regular template). If anyone is interested, the template can be found here: http://visualstudiogallery.msdn.microsoft.com/en-us/23df0450-5677-4926-96cc-173d02752313. These templates are simply T4 templates and easily changed. Also, I was able to use T4 and the EF object model to generate code for Flex. WebOrb has that builtin, but if you want to do it yourself there is another option.
|
|
Rank: Apprentice Coder Groups: Member
Joined: 8/20/2009 Posts: 24 Points: -31 Location: AllynWA
|
I too am struggling with the EntityFramework and passing objects to and from WebORB 5.0.0. My first approach was, as suggested, to detach the object, which works well going from .NET to Flex, but challenges the return trip. This is the code that gets the entity and sends it to Flex (via WebORB.net): Code: public ClientCompany GetClientByClientGUID(Guid clientGuid) { ClientCompany client = null;
try { using (masterContext = new SenVUMasterEntities()) { client = masterContext.ClientCompanies .Include("ClientAddresses") .Include("ClientConfigSettings") .Include("ClientGroups") .Include("ClientLicenseItems") .FirstOrDefault(c => c.ClientGUID == clientGuid);
// we need to detach the user from the context to // deal with lazy loading issues before returning if (client != null && DataHelper.IsAttachedTo(masterContext, client)) masterContext.Detach(client);
return client; } } catch (Exception ex) { SenVULogger.LogWarning(log, string.Format("GetClientByClientGUID error loading client guid {0}", clientGuid), ex); throw (ex); } } Flex 3 receives it fine into a VO I created. When I went to send it back from Flex to .NET, this was the original routine: Code: public void UpdateAddClientCompany(ClientCompany client) { if (client == null) throw new ArgumentNullException("ClientCompany cannot be null");
try { using (masterContext = new SenVUMasterEntities()) { object obj = null;
switch (client.EntityState) { case EntityState.Added: masterContext.AddToClientCompanies(client); break;
case EntityState.Detached: default: if (client.EntityKey != null && masterContext.TryGetObjectByKey(client.EntityKey, out obj)) masterContext.ApplyCurrentValues(client.EntityKey.EntitySetName, client); else masterContext.AddToClientCompanies(client); break; } masterContext.SaveChanges(); } } catch (Exception ex) { SenVULogger.LogWarning(log, "UpdateAddClientCompany error:", ex); throw (ex); } }
The problem lies in the (apparent) inability to transfer the EntityKey property to and from Flex (at least I haven't found the way yet...anyone?), especially when the entity was part of a collection List .
I re-coded the return trip to look like this:
Code: public void UpdateAddClientCompany(ClientCompany client) { object obj = null; ClientCompany checkClient;
if (client == null) throw new ArgumentNullException("Client company cannot be null");
try { using (masterContext = new SenVUMasterEntities()) { if (client.ClientGUID != null && client.ClientGUID.ToString() != string.Empty) { // we have a client guid so lets see if there is a client // already here checkClient = masterContext.ClientCompanies .FirstOrDefault(c => c.ClientGUID == client.ClientGUID);
if (checkClient != null) { // we have an existing client with the same guid // so this must be an update. Use that key in current object // TODO: find better WebORB solution(hack) client.EntityKey = checkclient.EntityKey; if (client.EntityKey != null && masterContext.TryGetObjectByKey(client.EntityKey, out obj)) { // save update masterContext.ApplyCurrentValues(client.EntityKey.EntitySetName, client); masterContext.SaveChanges(); } } else { // this client guid doesn't exist, so we're adding masterContext.AddToclientProfiles(client); masterContext.SaveChanges(); } } else { // we have an empty guid so see if we know the client's company name // (guaranteed unique in entity) if (client.ClientName != null && client.ClientName != string.Empty) { checkclient = masterContext.ClientCompanies .FirstOrDefault(c => c.ClientName == client.ClientName);
// client exists so barf if (checkClient != null) { throw new Exception(string.Format("Client already exists for Client Name {0}", client.ClientName)); } else { masterContext.AddToclientProfiles(client); masterContext.SaveChanges(); } } } } } catch (Exception ex) { SenVULogger.LogWarning(log, "UpdateAddclientProfile error:", ex); throw (ex); } }
It's not pretty, but I am able to get past the coding roadblock where I'm currently stuck.
Mark, any ideas? Anyone?
|
|
|
Guest |