【发布时间】:2016-07-14 15:12:37
【问题描述】:
我有一个实体框架模型,其中包含一个资产表,如下所示:
public partial class Asset
{
public int Switch { get; set; }
public string Port { get; set; }
public string Name { get; set; }
public string Connection { get; set; }
public string Interface { get; set; }
public string ConnectionUser { get; set; }
public string ConnectionDate { get; set; }
}
我试图只返回“名称”列。这是我用来这样做的代码:
// create the entity model for DB operations
acls3Entities entities = new acls3Entities();
List<Asset> assets = entities.Assets.ToList();
foreach (Asset asset in assets)
{
Console.WriteLine(string.Format("{0}", asset.Name));
};
但是,它给了我这篇文章标题中定义“资产”的行中引用的错误。我该如何解决这个问题?
【问题讨论】:
-
查看数据库中 Switch 列的类型,如果是 GUID,则将其更改为 int。
标签: c# asp.net entity-framework