在实体中创建非映射属性(实体框架) [英] Creating a non mapped property in an entity (entity framework)

查看:172
本文介绍了在实体中创建非映射属性(实体框架)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在从数据库映射的我的一个实体上创建一个自定义属性,但是这个属性没有映射到数据库,我使用部分类创建了属性,但是当尝试编译时,我收到一个错误,告诉我属性未映射。有什么属性还是我应该添加的东西?感谢提前。

解决方案

使用部分类添加要添加的属性或方法。例如

 命名空间WhateverNamespaceYourEntityModelIsIn 
{
public partial class TheNameOfYourEntity
{
public string MyNewProperty {get;组; }
}
}


I want to create a custom property on one of my entities mapped from the database, however this property is not mapped to the database, I created the property using partial classes but when trying to compile I get an error telling me that the property is not mapped. Is there an attribute or something I should add? Thanks in advance.

解决方案

Use partial classes to add the properties or methods you want added. E.g.

namespace WhateverNamespaceYourEntityModelIsIn
{
    public partial class  TheNameOfYourEntity
    {
          public string MyNewProperty { get; set; }
    }
}

and that should do you.

这篇关于在实体中创建非映射属性(实体框架)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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