Skip to main content
Home Forums Silverlight Programming WCF RIA Services Updating Child Entities, Possible Bug?
4 replies. Latest Post by atbacarat on July 8, 2009.
(0)
atbacarat
Member
13 points
40 Posts
07-08-2009 11:58 AM |
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
ColinBlair
Contributor
6611 points
1,298 Posts
07-08-2009 12:14 PM |
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?
07-08-2009 12:21 PM |
Just double checked and "LU_TeamStatus" has all unique values.
07-08-2009 12:28 PM |
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.
07-08-2009 1:11 PM |
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.