0

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 ;)

1
  • Do you imagine to see the dot in SQL or in C# ? Commented Mar 2, 2012 at 8:20

2 Answers 2

3

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");
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot Ntziolis. It seems it is not fixed. Unortunately I've tested all combinations with the schema. I have to say that 'MyNewSubProject' it's just a prefix in the table and not a real schema. If I put in schema 'dbo.MyNewSubProject' or 'MyNewSubProject' doesn't work. It's a bad decission use the dot?. If it's a special character in SQL...
yes, if you can eliminate the . do it, it is bad design to use reserved characters for names
3

try the following

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

this will change schema to MyNewSubProject

1 Comment

Thanks! Doesn't work :( ... 'MyNewSubProject' it's just a prefix and not a real schema.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.