Reputation: 4068
I'm migrating an LINQ to SQL project to EF 6.1.3 Code First. The problem I'm facing is:
I have 2 tables, Incidents with debtorNo column (varchar(20) not null) and Debtors With a No column (varchar(20) not null) which is the primary key. The schema cannot change because these tables are populated by an external system on which I have no control. There is no foreign key between the tables in the db as the tables are populated asynchronously (again no control over that). The db collation is case insensitive.
In LINQ to SQL I declared an association between the tables for navigation. In EF I declared the same association with the following code in the DbContext's OnModelCreating method:
modelBuilder.Entity<Incident>()
.HasRequired(e => e.Debtor)
.WithMany(e => e.Incidents)
.HasForeignKey(e => e.DebtorNo);
While LINQ to SQL association was case insensitive the EF association is not. After googling the problem I found 2 solutions:
These solutions are perfectly working (I'll probably use the second one) but were dated a couple of years ago and referred to EF 4.1 Code First.
So my question is is there a way to declare a case insensitive string association in the latest version of EF Code First?
Upvotes: 2
Views: 1766
Reputation: 1769
We are using EF 6.1 and, as far as I can determine, there is no way to do this. I think you will still need to use one of the methods you listed.
FWIW we are using views to do conversions at the database level (strings to dates for example)
Upvotes: 3