c# - Entity Framework Code First - How to ignore a column when saving -


i have class called client mapped database table using entity framework code first. table has computed field need available in client class, understand won't possible write field. there way of configuring entity framework ignore property when saving, include property when reading?

i have tried using ignore method in configuration class, or using [notmapped] attribute, these prevent property being read database.

you can use databasegeneratedattribute databasegeneratedoption.computed option:

[databasegenerated(databasegeneratedoption.computed)] public computedpropertytype computedproperty { get; set; } 

or if prefer fluent api can use hasdatabasegeneratedoption method in dbcontext class:

public class entitiescontext : dbcontext {     public dbset<entitytype> enities { get; set; }      protected override void onmodelcreating(dbmodelbuilder modelbuilder)     {         modelbuilder.entity<entitytype>().property(e => e.computedproperty).hasdatabasegeneratedoption(databasegeneratedoption.computed);     } } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -