Reputation: 323
I am developing a web-based system using .NET MVC and Entity Framework, from a legacy system. I will keep the legacy database and only develop the application, so I will create entity classes using database first approach.
My concern is, in the entity classes, I will be adding attributes such as filter attributes. And I may add some extra fields there as well. Will the database be updated automatically? I actually don't want to update the database at all. I only want extra stuff stay with the entity class only.
Upvotes: 1
Views: 1426
Reputation: 33
Maybe you should consider using partial classes. I find editing anything in EF quite hard.
EF Classes from your DB are all :
public partial myClass(){
public string myDBProperty;
}
Which means you are able to create a second class in the same namespace like :
public partial myClass(){
public string myOwnProperty;
}
Upvotes: 0
Reputation: 1117
First, when adding additional properties in your entity classes you will want to mark them for EF to ignore using either the [NotMapped] attribute or in your DbContext class calling .Ignore on the property. Not Mapped Attribute
Second, in terms of EF changing your database you can do a couple of things. 1. Ensure the account that is updating data does not have Create,Alter,etc permissions in the environment 2. Use a null database initializer at the beginning of your application. Database.SetInitializer(null); Setting the initializer to null tells EF not to make any sort of changes to the database. Turn off DB Initializer
Upvotes: 1
Reputation: 33
You can easily create your database first and then start working on the backend side of your application as you would do it in an "Code first" approach. I'd recommend reading this article, as you might get all your answers cleared with some examples: Entity framework
Upvotes: 2