Search code examples
c#asp.netentity-frameworkef-code-first

Business-logic type methods in Entity Framework Code First approach classes


I would like to know if it is possible to add domain specific methods on model classes which works with Entity Framework Code First approach.

For example, the following dummy method:

public class Student
{
    public Student()
    { 

    }

    public int StudentID { get; set; }
    public string StudentName { get; set; }

    // Dummy method
    public string StudentNamePlusALetter(string letter)
    {
        return (this.StudentName + letter)
    }
}

If is not possible, where am I supposed to add them?

Thank you in advance.


Solution

  • Of course it is, with the caveat that the value of StudentNamePlusALetter() won't be stored in your database (since only properties get serialized down there).