开发者

Need a new virtual property that returns value based upon two physical properties

开发者 https://www.devze.com 2023-03-13 06:05 出处:网络
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 m

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消