Jacob
Jacob

Reputation: 1896

Table name with dot in CodeFirst

I thought that it was a good idea to prefix some of my tables with the name of the area:

MyNewSubProject.Table1
MyNewSubProject.Table2

Unfortunately when I'm going to map these tables with Entity Framework Code First with the model builder:

modelBuilder.Entity<Entity>().ToTable("MyNewSubProject.Table1");

Throws the exception:

(System.Data.Entity.Infraestructure.DbUpdateException)
{"Invalid object name 'MyNewSubProject.Table1'."}

The table name is correct. I've tried to add the schema but no luck. If I remove the dot everything goes great.

Any way to use the dot?

Thanks ;)

Upvotes: 0

Views: 1598

Answers (2)

ntziolis
ntziolis

Reputation: 10221

Apparently the DDL commands don't properly wrap the object identifiers.

Try wrapping the Table name in [MyNewSubProject.Table1].

This was a know issue, I assumed this was fixed by now:
http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/thread/9c5642ad-3e4e-496f-9721-059071d653e3

UPDATE

Apparently you can set the schema seperately like this:

modelBuilder.Entity<Entity>().ToTable("Table1", "MyNewSubProject");

Upvotes: 3

Jayanga
Jayanga

Reputation: 887

try the following

modelBuilder.Entity<Entity>().ToTable("Table1","MyNewSubProject");

this will change schema to MyNewSubProject

Upvotes: 3

Related Questions