ASP.NET MVC is data access agnostic, meaning the framework doesn't really have anything to do with the database access technology. It is made to work with any method of providing data, as long as you return models. How are you doing the database access?
EF Code first (dbcontext) ? If that's the case this issue relates to EF Code First and i know that you can specifiy additional parameters to the EF context to control how tables are generated.
That may be my issue. I have already created the database and tables, so code first won't work in this situation. As a first-time MVC developer I have no idea how to turn that on or off.
I have a class in the Models folder which has a public method implementing DbContext. Does that answer your question?
Yes, so you are using EF Code First with an existing Database. You need to tell Code First how to map to the database tables manually.
By default it uses the dbo schema, what you have to do is tell the framework which schema to use instead. You need to decorate your model with the Table attribute to tell EF Code first which table and schema to use.
[Table("TableName", Schema = "myUser")]
public class TableName{
//
}
alockrem
Member
206 Points
203 Posts
How do I change my MVC application from looking at dbo.TableName to myUser.TableName?
Apr 11, 2012 04:59 PM|LINK
Thank you for any help.
CodeHobo
All-Star
18647 Points
2647 Posts
Re: How do I change my MVC application from looking at dbo.TableName to myUser.TableName?
Apr 11, 2012 05:34 PM|LINK
ASP.NET MVC is data access agnostic, meaning the framework doesn't really have anything to do with the database access technology. It is made to work with any method of providing data, as long as you return models. How are you doing the database access? EF Code first (dbcontext) ? If that's the case this issue relates to EF Code First and i know that you can specifiy additional parameters to the EF context to control how tables are generated.
Blog | Twitter : @Hattan
alockrem
Member
206 Points
203 Posts
Re: How do I change my MVC application from looking at dbo.TableName to myUser.TableName?
Apr 11, 2012 05:44 PM|LINK
That may be my issue. I have already created the database and tables, so code first won't work in this situation. As a first-time MVC developer I have no idea how to turn that on or off.
I have a class in the Models folder which has a public method implementing DbContext. Does that answer your question?
CodeHobo
All-Star
18647 Points
2647 Posts
Re: How do I change my MVC application from looking at dbo.TableName to myUser.TableName?
Apr 11, 2012 06:09 PM|LINK
Yes, so you are using EF Code First with an existing Database. You need to tell Code First how to map to the database tables manually.
By default it uses the dbo schema, what you have to do is tell the framework which schema to use instead. You need to decorate your model with the Table attribute to tell EF Code first which table and schema to use.
[Table("TableName", Schema = "myUser")] public class TableName{ // }Take a look at this
http://stackoverflow.com/questions/7184577/specify-an-sql-username-other-than-dbo-in-code-first-entity-framework-c-sharp
Blog | Twitter : @Hattan
alockrem
Member
206 Points
203 Posts
Re: How do I change my MVC application from looking at dbo.TableName to myUser.TableName?
Apr 11, 2012 06:20 PM|LINK
Perfect! Thank you very much. I really appreciate your help.