Entity Framework Code First: How To Map Sql Server's Computed Columns Into Cf Model?
Is it possible to map computed columns into Code First model? I'd like to define computed columns with SQL Server and then map them as properties inside my CF model. Thanks in adva
Solution 1:
Use the DatabaseGenerated attribute with DatabaseGeneratedOption.Computed as the value
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
publicstring Foo { get; set; }
Solution 2:
Not sure how you would do computed columns without using a view, and you cannot use views in EF Code First (you can in Model & DB first though). EF will execute some operations in SQL for you, instead of in code, but it doesn't sound like that is what you're looking for. Can you elaborate on what you are trying to achieve?
Post a Comment for "Entity Framework Code First: How To Map Sql Server's Computed Columns Into Cf Model?"