I have a 3rd party database where the primary key is a char datatype. When I run my query, I use an include to include the child table. The count is zero though. I look at sql profiler and results are returned. The only thing I can see is an issue with the relationship columns being char. Any solution for this?
A:
Be careful with the Char type. "1234 " != "1234"! The DB may not notice this, but the EF does.
Craig Stuntz
2009-10-20 17:59:11
The records returned from the database is what is in the database though, right? Even though the query may ask for 1234, the results returned from the query are "1234 " for the parent and "1234 " from the child, right?
Marsharks
2009-10-20 18:03:43
Depends on your DB, I guess. SQL Standard says include the spaces. (As opposed to VARCHAR, which doesn't require them.)
Craig Stuntz
2009-10-20 19:12:34
So my relationships still don't work with char.
Marsharks
2009-10-20 20:01:18
A:
I found a work around. If I use in my query to select from the child and include the parent, get the first child in the list, then get a reference to the parent, I am able to get the parent with all the child.
var query = from l in Context.LicenseItems
.Include("License")
Marsharks
2009-10-21 20:55:57
Char is a red herring, then. Here's the actual issue you're dealing with: http://blogs.msdn.com/alexj/archive/2009/06/02/tip-22-how-to-make-include-really-include.aspx
Craig Stuntz
2009-10-22 12:35:52