Skip to main content

Microsoft Silverlight

Answered Question Updating Child Entities, Possible Bug?RSS Feed

(0)

atbacarat
atbacarat

Member

Member

13 points

40 Posts

Updating Child Entities, Possible Bug?

Ok Guys,

I'm finally able to update child entities now if a make sure I have the proper CRUD operations for each entity in my datamodel and ONLY if I format my query's in a certain way it seems that you must use .First rather than .Single, Someone correct me if im doing soemthing wrong here but this is what finally got it working for just FYI for anyone who was having trouble with updating child entity's using the RIA framework and a DomainDataSource in this way. Thanks again to ColinBlaire and Theo67for your help with this.

 

Please look at the following code, is this possibly a bug? Anyone have any ideas on this?

 

The following code will update the child entity LU_TeamStatus using a).first:

Public Sub CancelTeam(ByVal current As tbl_TeamSchedule)
If current.EntityState = EntityState.Detached Then
Me
.Context.Attach(current)
End If

Dim
CancelTeam = (From a In Context.LU_TeamStatus _
Where a.TeamStatusID = 2 _
Select a).First

current.LU_TeamStatus = CancelTeam
End Sub
 

The following code will NOT update the child entity and just hangs when trying to update the child entity LU_TeamStatus using a).single

Public Sub CancelTeam(ByVal current As tbl_TeamSchedule)
If current.EntityState = EntityState.Detached Then
Me
.Context.Attach(current)
End If

Dim
CancelTeam = (From a In Context.LU_TeamStatus _
Where a.TeamStatusID = 2 _
Select a).Single

current.LU_TeamStatus = CancelTeam
End Sub
  

-Bacarat

http://www.facebook.com/ChadMCorrin : A link to my Facebook page

ColinBlair
ColinBlair

Contributor

Contributor

6611 points

1,298 Posts

Re: Updating Child Entities, Possible Bug?

The primary difference between .First and .Single is that .Single will throw an exception if there is not exactly one row in the results. Are you sure you don't have a duplicate row in LU_TeamStatus?

-Colin Blair

http://www.RiaServicesBlog.net : The Elephant Guide to RIA Services
SLColinBlair on Twitter

atbacarat
atbacarat

Member

Member

13 points

40 Posts

Re: Updating Child Entities, Possible Bug?

Just double checked and "LU_TeamStatus" has all unique values.

-Bacarat

http://www.facebook.com/ChadMCorrin : A link to my Facebook page

ColinBlair
ColinBlair

Contributor

Contributor

6611 points

1,298 Posts

Answered Question

Re: Updating Child Entities, Possible Bug?

Some more things to try. First, you need to put a type in for CancelTeam. You aren't creating a query, you are executing one so you need to strongly type your result. Second, put in a try catch so that if the Single is throwing an exception you can put in a breakpoint and see it. Third, do a .Count on that LINQ query and see how many results are coming through.

-Colin Blair

http://www.RiaServicesBlog.net : The Elephant Guide to RIA Services
SLColinBlair on Twitter

atbacarat
atbacarat

Member

Member

13 points

40 Posts

Re: Updating Child Entities, Possible Bug?

 Thanks Colin,

I think I already knew this one from working with webforms but it didnt click until just now. Try and catch returns the following exception:

The method 'Single' is not supported by LINQ to Entities. Consider using the method 'First' instead.

 I had forgotten that .Single was not supported. This was probably the issue the whole time, but the exception was not thrown until I put in the try & catch.

 

-Bacarat

http://www.facebook.com/ChadMCorrin : A link to my Facebook page
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities