【问题标题】:A field in the model with not counterpart in DB throws "Invalid column name"模型中的字段与 DB 中不对应的字段抛出“无效的列名”
【发布时间】:2012-04-23 15:28:17
【问题描述】:

我正在尝试定义一个不在我的数据库中的字段。 它的形式是这样的:

public string Adress {get;set;}
public int? Number {get;set;}
public string Name {get{
    return (this.Adress + " " + this.Number.ToString())
} set{}}

...当我运行索引(其模型为 IEnumerable 类型)时,控制器会抛出...

Invalid column name 'Name'.

我想这样做,所以我不必每次都连接所有这些。

我正在使用 ASP.NET MVC3 和 SQL Server 2008。

有没有办法告诉模型我没有具有该名称的列?

【问题讨论】:

  • 您能否更具体地说明您在做什么,您正在使用什么技术等。你什么时候收到这个错误?当它发生时你在做什么?

标签: sql-server asp.net-mvc asp.net-mvc-3


【解决方案1】:

我发现了如何做到这一点。

可以使用 [NotMapped] 属性进行管理。

【讨论】:

    猜你喜欢
    • 2021-01-13
    • 2016-03-06
    • 1970-01-01
    • 2020-08-16
    • 1970-01-01
    • 2016-03-09
    • 1970-01-01
    • 2013-11-29
    • 2018-03-11
    相关资源
    最近更新 更多