ASP.NET的MVC 4实体框架数据库第一个覆盖模型属性类型 [英] asp .net mvc 4 Entity Framework database first override model property type
问题描述
使用C#,ASP.NET的MVC 4,实体框架5和数据库第一。我如何可以覆盖一个属性或一个新的属性添加到模型类的?下面你可以看到在类型作为一个字节,但我不能显示该字节的用户,我想展示一个友好的名称。类型描述并不在数据库中,它被存储在字典中。
命名空间Cntities
{
公共部分类MyClass的
{
公众诠释标识{搞定;组; }
公共字符串名字{获得;组; }
公共字符串名字{获得;组; }
公共字节类型{搞定;组; }
}
}
由于类是局部的,你可以展开和添加自己的属性和方法只是确保其在同一位置作为当前局部文件中定义。
命名空间Cntities
{
公共部分类MyClass的
{
公共字符串DisplayValue {获得{
回到格式化; // 一个例子
}
}
}
看看 http://msdn.microsoft.com/en-美国/库/ wa80x488.aspx
Using C#, ASP .Net MVC 4, Entity Framework 5 and Database First. How can I override a property or add a new property to a model class? Below you can see the "Type" as a Byte, but I can't display the byte to the users and I want to display a friendly name. The Type description is not in the database, it is stored in a dictionary.
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; }
}
}
Since the class is a partial you can expand and add your own properties and methods just ensure its defined in the same location as your current partial file.
namespace Cntities
{
public partial class myClass
{
public string DisplayValue{ get {
return "Formated"; // An example
}
}
}
Take a look at http://msdn.microsoft.com/en-us/library/wa80x488.aspx
这篇关于ASP.NET的MVC 4实体框架数据库第一个覆盖模型属性类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!