Reputation: 2253
I have model which directly update my DB.
But some properties I do not want to update in my DB table then how can I mark those properties to not to go in DB table?
my model is as below:
public class Blog
{
public int id {get;set;}
public int newid {get;set;} // which i want to unbind/exclude
}
Upvotes: 2
Views: 1603
Reputation: 2253
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Customer>().Ignore(t => t.LastName);
base.OnModelCreating(modelBuilder);
}
Upvotes: 2
Reputation: 1038930
Assuming that you are using Entity Framework (which by the way you should have specified in your question because ASP.NET MVC doesn't know what a database means. I remind you that ASP.NET MVC is a web framework, not an ORM), you could decorate the property with the [NotMapped]
attribute:
public class Blog
{
public int id { get; set; }
[NotMapped]
public int newid { get; set; }
}
Obviously if you are using some other data access technology to query your database you should check the documentation of it to know how to ignore some properties from being mapped.
Upvotes: 7