Linq to SQL: combine two columns to make a readonl

2019-08-28 06:06发布

问题:

Basically, it's the simple scenario of needing to populate a dropdown with LastName, FirstName by combining the two columns in the entity to FullName. I'd like it to live in the entity so I can grab it whenever I find a use for it. Is this possible?

回答1:

I would add a partial class that has the FullName property. Have a look at the designer file for your data context classes for the namespace and partial classname to use.

namespace your.namespace {

  public partial class yourclassname {
      public string FullName {
          get { return string.format("{0} {1}", FirstName, LastName); }
      }
  }

}


标签: linq-to-sql