Linq to SQL:合并两列以创建一个只读的自定义列 [英] Linq to SQL: combine two columns to make a readonly custom column

查看:59
本文介绍了Linq to SQL:合并两列以创建一个只读的自定义列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,这是一个简单的场景,需要通过将实体中的两列组合为FullName来用LastName,FirstName填充下拉列表.我希望它可以存在于实体中,以便在我发现有用途时可以抓住它.这可能吗?

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?

推荐答案

我将添加一个具有FullName属性的局部类.查看数据上下文类的设计器文件,以使用命名空间和部分类名.

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:合并两列以创建一个只读的自定义列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆