Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extending an entity framework model

i want extend an entity framework model with a temporany attribute. I need it only in a mvc form. I don't need save it in the db.

How can i do it?

like image 838
Luca Romagnoli Avatar asked Sep 11 '26 22:09

Luca Romagnoli


1 Answers

Create a partial class for the entity you want to extend

e.g.

//must be in the same namespace as the Customer entity in the model
public partial class Customer
{
     public string MyProperty{get;set;}
}

This property will be unmapped and you can fill it with data after you run a query or on materialization.

OR

Create a wrapper class for your entity which expose both the unmapped property and the mapped properties the properties you need in the view.

like image 119
Roger Johansson Avatar answered Sep 15 '26 02:09

Roger Johansson