0

When I use database first, after creating the edmx file, all the conceptual models have already been generated. But I want to do some special operations on certain fields. For example, there's a field named 'price'; I want the matching property 'Price' to return double of the 'price'. How can I do that? If I modify the getter in the code, every time I update the model from database, all of the modifications go away.

What's the correct way to do this?

mjk
  • 2,443
  • 4
  • 33
  • 33
James
  • 2,570
  • 7
  • 34
  • 57

1 Answers1

2

What you can do is create a partial class for entity which contains the Price Property and put a getter like this (A property with double price will be meaningful ),

Public partial class YourEntity{
  Public float DoublePrice{
    get { return Price*2;}
 }
}

Or you can create a class inherited from the entity,

 Public partial class Entity:YourEntity{
      Public override float Price{
        get { return base.Price*2;}
     }
  }
Jayantha Lal Sirisena
  • 21,216
  • 11
  • 71
  • 92
  • Hi, thanks for your quick reply, if I create a partial class, how about the auto-generated property? remove it? If I update model from database, the property will appear again. – James May 03 '12 at 03:32
  • No I mead you can keep it. It will be more meaningful if you have two properties `Price` and `DoublePrice` ? – Jayantha Lal Sirisena May 03 '12 at 03:33
  • Oh, sorry for my ignorant of the property name you posted, thanks, Jayantha! – James May 03 '12 at 04:30