I’m trying to connect to an SQL Server 2008 database in a shared hosting environment from C# from within an ASP.NET MVC 3 application connecting via EF (code first).
My problem is that the generated SELECT statement looks like so:
SELECT ... FROM [dbo].[TableName]
which throws the error Invalid object name, but works fine when I do:
SELECT ... FROM [mySQLUserName].[TableName]
How do I specify a username other than dbo (e.g. mySQLUserName)?
EDIT:
The closest articles I have found that are relevant to this issue are:
- http://weblogs.asp.net/scottgu/archive/2010/08/03/using-ef-code-first-with-an-existing-database.aspx
- http://weblogs.asp.net/scottgu/archive/2010/07/23/entity-framework-4-code-first-custom-database-schema-mapping.aspx
with specific emphasis on the second article, however it doesn’t specify how to set a username other than dbo
You can specify the schema using a property on the
TableAttributethat decorates your entity classes.