I thought I’d try the new DbContext way of doing things in EF 4.1, but ran into a problem.
I generate a new entity data model from database (SQL Server 2008) and then I use the DbContext generator.
When I try to fetch the table called Länder i get an exception.
var db = new MyEntities(); // instantiate DbContext subclass
var countries = db.Länder.ToList(); // boom
EntitySqlException: The simple identifier ‘Länder’ must contain basic Latin characters only. To use UNICODE characters, use an escaped identifier.
If if try other tables with latin names – all is fine. And I don’t have this problem when using ObjectContext.
How am I supposed to escape the table name?
We (the EF team) investigated and found that we were not properly escaping (i.e. adding square brackets) for the names of the entity sets when we bootstrap the DbSets.
Thanks a lot for reporting this!
We are currently testing a fix that should be included in a future release. In the meanwhile, you should be able to workaround this by specifying the entity set name explicitly such that it doesn’t contain any characters that would need escaping.
When using Database First or Model First this can be done by editing the entity set names in the designer. When using Code First, it can be done by changing the name of the DbSet property:
or by overriding OnModelCreating in the context: