Kyle Abrahams, PMP
asked on
Linq to Entities (3.5) Children not loading
Hi All,
I'm trying to convert from linq to sql to linq to entities as my team doesn't like the code being tightly coupled (no complaints).
I'm running into issues where I can't load the associated child record.
I manually created an association from the Order table to the Label_Proof table. It's a one to one.
dm is my instance of the entity
I'm trying to do:
dim lp as Label_Proof = dm.Orders.Include("Label_P roof").Whe re(Functio n(o As Order) o.Order_Number = RunCode).FirstOrDefault.La bel_Proof
but lp is always coming back nothing.
However if I take out the where clause and just do:
dm.Orders.Include("Label_P roof").Fir stOrDefaul t.Label_Pr oof
it comes back fine.
I have verified that the label_proof actually exists for the runcode in question. I can assign the order to a variable and do a manual lookup on label proofs, but that seems cumbersome.
Note this is EntityFrameworks 1 using .Net 3.5 in VS2008.
Any and all help greatly appreciated.
I'm trying to convert from linq to sql to linq to entities as my team doesn't like the code being tightly coupled (no complaints).
I'm running into issues where I can't load the associated child record.
I manually created an association from the Order table to the Label_Proof table. It's a one to one.
dm is my instance of the entity
I'm trying to do:
dim lp as Label_Proof = dm.Orders.Include("Label_P
but lp is always coming back nothing.
However if I take out the where clause and just do:
dm.Orders.Include("Label_P
it comes back fine.
I have verified that the label_proof actually exists for the runcode in question. I can assign the order to a variable and do a manual lookup on label proofs, but that seems cumbersome.
Note this is EntityFrameworks 1 using .Net 3.5 in VS2008.
Any and all help greatly appreciated.
ASKER
Hi Learned,
1)
I'm using Visual Studios 2008. The Web service is for a Handheld using Windows 6.5.3 mobile OS so 3.5 is the only .net version supported (to my knowledge).
I believe I'm using version 1, but is there a way to check?
2)
How do I check that?
Familiar with Linq to SQL but we wanted to get away from being so tightly coupled to the DB. First time in the EF.
1)
I'm using Visual Studios 2008. The Web service is for a Handheld using Windows 6.5.3 mobile OS so 3.5 is the only .net version supported (to my knowledge).
I believe I'm using version 1, but is there a way to check?
2)
How do I check that?
Familiar with Linq to SQL but we wanted to get away from being so tightly coupled to the DB. First time in the EF.
If you didn't install anything extra, then you would have version 1, since that was the version that came with 2008.
ADO.NET Entity Framework
http://en.wikipedia.org/wiki/ADO.NET_Entity_Framework
That was the version that I never used, because it had so many problems. Can you describe what you mean by "tightly coupled"? What are you looking for in a framework?
ADO.NET Entity Framework
http://en.wikipedia.org/wiki/ADO.NET_Entity_Framework
That was the version that I never used, because it had so many problems. Can you describe what you mean by "tightly coupled"? What are you looking for in a framework?
ASKER
I originally built the web service using LinqToSql. But after changing some columns around, the program broke because it was looking for references to those columns. I've noticed in LinqToSQL that even if the column orders are off, things will break.
So I switched it from LinqToSql to LinqToEntities, rebuilding my DBML into a EDMX. When I did that however, my linq queries (like the one above) started breaking.
I'm definitely using the 3.5 version so that would be version 1.
We were trying to keep the handheld and the web service together, so I was told to not upgrade the service part of it to 4.0.
The good news is that I got it working by implementing the work arounds. The bad news is I feel it's highly inefficient (essentially making another lookup call rather than loading the child object at the same time).
Does this look okay and does it work in the later versions of EF?
'key to look for of the parent
dim key as integer
' the reference to the EDMX
dim dm as DataBaseModelEntities
'get the child.
dim c as Child = dm.ParentTable.Include("Ch ild_Table" ).Where(Fu nction(p As Parent) p.Key = theKey).FirstOrDefault.Chi ld
So I switched it from LinqToSql to LinqToEntities, rebuilding my DBML into a EDMX. When I did that however, my linq queries (like the one above) started breaking.
I'm definitely using the 3.5 version so that would be version 1.
We were trying to keep the handheld and the web service together, so I was told to not upgrade the service part of it to 4.0.
The good news is that I got it working by implementing the work arounds. The bad news is I feel it's highly inefficient (essentially making another lookup call rather than loading the child object at the same time).
Does this look okay and does it work in the later versions of EF?
'key to look for of the parent
dim key as integer
' the reference to the EDMX
dim dm as DataBaseModelEntities
'get the child.
dim c as Child = dm.ParentTable.Include("Ch
Do you have the possibility (or the inclination) to look into NHibernate, and AutoMapper?
ASKER
I accept the fact that the first implementation is horrible. AutoMapper would be objected to due to cost (I'm sure we don't want to expose our schema).
NHibernate looks interesting, and had I'd known about it maybe would have tried, but doesn't really answer the question of how to go about doing this correctly in EF1.
Did they provide for the ability to do this at all? How would this be done in EF4?
NHibernate looks interesting, and had I'd known about it maybe would have tried, but doesn't really answer the question of how to go about doing this correctly in EF1.
Did they provide for the ability to do this at all? How would this be done in EF4?
Children for associations should be loaded, unless lazy loading is used. I would have thought that the first version of EF would have supported that, but I am not sure that I completely understand your environment.
ASKER
How do I determine if lazy loading is being used?
What else do you need to know about the environment? Appreciate the help.
What else do you need to know about the environment? Appreciate the help.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help.
2) Is the data context set up for lazy loading?