I have a complicated structure of tables and I need some work done extra so I am using partial classes on my entities from EF.
Lets say I have an entity called Person with attributes Name and LastName. Querying over the entity will return me a collection of persons with the name and lastname. Now I would like to have also a property FullName which I create using a partial class of the class person. Since all of the data is in the object I can easily get it.
public partial class Person
{
public string FullName { get { return Name + " " LastName } }
}
Now things get complicated..... Lets Supose that I have also another Entity (Car) that is connected to Person.
Change the request so the Name of the Car is also a part of the fullName.
public partial class Person
{
public string FullName { get { return Name + " " LastName + " - " + Car.Name } }
}
My problem is the following: since the EF Context is already disposed after the using I would like to have it executed in runtime while querying and stored inside the object but not inside the database. Something like a custom ToString
method.
I need this for GUI purposes. Of course this is a simplified version of it and format string in the gui and query would be much easier, but they are not an option.
I need to find a way to have it automatically returned, or at least have a method automatically executed.
I could achieve this by overriding the constructor, or overloading it maybe, from where I could call a method. I would really prefer not to go through every single object of the query result and invoke the Method from a loop, or creating the context if it does not exist in the getter.
I repeat, this is a simplified version of the problem