views:

36

answers:

2

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
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
Depends on your DB, I guess. SQL Standard says include the spaces. (As opposed to VARCHAR, which doesn't require them.)
Craig Stuntz
So my relationships still don't work with char.
Marsharks
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
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