【问题标题】:asp .net mvc 4 Entity Framework database first override model property typeasp .net mvc 4 Entity Framework 数据库首先覆盖模型属性类型
【发布时间】:2014-01-06 22:29:04
【问题描述】:

使用 C#、ASP .Net MVC 4、Entity Framework 5 和 Database First。如何覆盖属性或向模型类添加新属性?您可以在下面看到“类型”为字节,但我无法向用户显示字节,我想显示一个友好的名称。类型描述不在数据库中,它存储在字典中。

namespace Cntities
{
  public partial class myClass
  {
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public byte Type { get; set; }    
  }
}

【问题讨论】:

    标签: entity-framework asp.net-mvc-4


    【解决方案1】:

    由于该类是部分类,因此您可以扩展并添加自己的属性和方法,只需确保将其定义在与当前部分文件相同的位置即可。

    namespace Cntities
    {
    public partial class myClass
    {
        public string DisplayValue{ get {
              return "Formated"; // An example
        }
    }
    }
    

    看看http://msdn.microsoft.com/en-us/library/wa80x488.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-30
      • 1970-01-01
      • 1970-01-01
      • 2011-05-30
      • 1970-01-01
      相关资源
      最近更新 更多