Specify an SQL username other than dbo in Code First Entity Framework ( C# ASP.NET MVC 3 )

前端 未结 5 1739
梦毁少年i
梦毁少年i 2020-12-31 06:41

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

<
5条回答
  •  情话喂你
    2020-12-31 06:55

    You don't say which version of EF you're using. If you're using Code First (4.1) you can specify the schema on a table attribute:

    [Table("Users", Schema = "myschema")]
    public class User { .. }
    

    You can use Scott's article (the second one) as a basis, but you add an additional parameter. ie.:

    modelBuilder.Entity().ToTable("TableName", "SchemaName"); 
    

提交回复
热议问题