Need a new virtual property that returns value based upon two physical properties
I have a couple of basic table in my database that store names as FirstName and LastName. Almost every table that has a person's name, it is being stored as FirstName and LastName. Now while I LINQ my way through the application, I realize that I am constantly using the combination in .Where()
and .OrderBy()
and I’m wondering if I can inject a method into the DBContext that 开发者_JAVA百科can return me FirstName + " " + LastName
as FullName column for all such entities (tables)
Any ideas?
Right-click on appropriate .dbml file and select View Code. You should see a partial class created for you for the table. In that class add a new property that just returns the full name.
public string FullName { get { return this.FirstName + this.LastName; } }
You will then be able to access FullName everywhere in the code.
精彩评论