C# 执行Linq查询时未找到模型属性
尝试从SQL server数据库获取模型的属性时遇到问题。我已经在我的模型上定义了属性,但是当我执行Linq查询时,它不允许我获取该属性 这是我的模型:C# 执行Linq查询时未找到模型属性,c#,asp.net,asp.net-mvc-4,C#,Asp.net,Asp.net Mvc 4,尝试从SQL server数据库获取模型的属性时遇到问题。我已经在我的模型上定义了属性,但是当我执行Linq查询时,它不允许我获取该属性 这是我的模型: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Web.Mvc;
namespace ProgramaAlimenticio.Models
{
public class RutaMD
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public virtual int pk_ruta { get; set; }
[Display(Name = "Ruta")]
public virtual string nombre { get; set; }
[Display(Name = "Proveedor")]
public virtual Nullable<int> fk_proveedor { get; set; }
[Display(Name = "Programa")]
public virtual int fk_programa { get; set; }
}
[MetadataType(typeof(RutaMD))]
public partial class Ruta { }
}
假设
db.Ruta
中有Ruta
项,而不是rutadm
项,那么您的Ruta
类似乎没有fk_programma
属性
[MetadataType(typeof(RutaMD))]
public partial class Ruta { }
也许这个属性应该在partial类的另一半中:您是否仔细检查过它是否确实存在?这是公开的吗?名字是一样的吗?它有一个get
ter?而且get
ter是公共的?什么是“问题”?是否发生异常?例外情况是什么?
[MetadataType(typeof(RutaMD))]
public partial class Ruta { }