Entity Framework and associations between string keys
Posted
by fredrik
on Stack Overflow
See other posts from Stack Overflow
or by fredrik
Published on 2009-04-06T15:04:54Z
Indexed on
2010/04/11
12:43 UTC
Read the original article
Hit count: 262
Hi, I am new to Entity Framework, and ORM's for that mather. In the project that I'm involed in we have a legacy database, with all its keys as strings, case-insensitive.
We are converting to MSSQL and want to use EF as ORM, but have run in to a problem.
Here is an example that illustrates our problem:
TableA has a primary string key, TableB has a reference to this primary key.
In LINQ we write something like:
var result = from t in context.TableB select t.TableA;
foreach( var r in result )
Console.WriteLine( r.someFieldInTableA );
if TableA contains a primary key that reads "A", and TableB contains two rows that references TableA but with different cases in the referenceing field, "a" and "A".
In our project we want both of the rows to endup in the result, but only the one with the matching case will end up there.
Using the SQL Profiler, I have noticed that both of the rows are selected.
Is there a way to tell Entity Framework that the keys are case insensitive?
Edit:
We have now tested this with NHibernate and come to the conclution that NHibernate works with case-insensitive keys. So NHibernate might be a better choice for us.
I am however still interested in finding out if there is any way to change the behaviour of Entity Framework.
© Stack Overflow or respective owner