Entity framework is used to add methods to a model.

.net c# entity-framework orm

Question

With entity framework, is it possible to add methods to an object class ? For example, i have a CLIENT mapping and i would like to create a "getAgeFromBirhDate" method.

1
16
5/30/2014 8:06:00 AM

Accepted Answer

Yes. It's possible. Entity Framework generates Partial Classes.

That means you can create another file that contains another portion of the Partial Class definition (with your additional methods) and everything will work just fine.

24
11/30/2010 2:56:50 PM

Popular Answer

An example for first answer:

if you have an entity named Flower you can use this partial class for adding method to it:

namespace Garden //same as namespace of your entity object
{
    public partial class Flower  
    {
        public static Flower Get(int id)
        { 
            //
        }
    }
}


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow