MVC3:属性不映射属性设置为数据库列 [英] MVC3: Attribute for not mapping a property to a DB column

查看:80
本文介绍了MVC3:属性不映射属性设置为数据库列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET MVC3。我有有,我不希望在数据库中存储一个属性的模式。有没有办法,我可以把属性来实现这个属性?谢谢你。


解决方案

 公共类Person
{
    [键]
    公众诠释标识{搞定;组; }
    公共字符串名字{获得;组; }
    公共字符串名字{获得;组; }    [NotMapped]
    公共字符串全名{获得;组; }
}

属性都是在命名空间 System.ComponentModel.DataAnnotations

I’m using ASP.NET MVC3. I have a model that has one property that I don’t want to store in the database. Is there an attribute that I can put on the property to achieve this? Thanks.

解决方案

public class Person
{
    [Key]
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }

    [NotMapped]
    public string FullName { get; set; }
}

The attribute are in the namespace System.ComponentModel.DataAnnotations

这篇关于MVC3:属性不映射属性设置为数据库列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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