【发布时间】:2011-10-08 21:20:39
【问题描述】:
我被困在我的 ASP.NET MVC 3 应用程序的某个地方。这是我得到的错误:
不支持指定的类型成员“AccommPropertyTags” LINQ 到实体。只有初始化器、实体成员和实体 支持导航属性。
我在下面的文章中找到了解决这个问题的方法:
Only initializers, entity members, and entity navigation properties are supported
但我的有点奇怪。
这是我的实体的部分类之一:
[MetadataType(typeof(AccommPropertyWebDetail.MetaData))]
public partial class AccommPropertyWebDetail {
public virtual ICollection<string> AccommPropertyTags {
get {
return Helpers.AccommPropertyTag.CreateStringListFromString(this.PropertyTags);
}
}
private class MetaData {
[Required, StringLength(50)]
public string Category { get; set; }
}
}
正如您在上面看到的,AccommPropertyTags 属性是 typeof ICollection<string>。我在控制器中尝试的内容如下:
public ViewResult Tag(string tag) {
var _rawTag = HttpUtility.UrlDecode(tag);
ViewBag.Tag = _rawTag;
var model = _accommpropertyrepo.GetAllAccommPropertiesFullWebIgnoringApprovalStatus();
model = model.Where(
x => x.AccommPropertyTags.Any(
y => y == _rawTag
)
);
return View(model);
}
由于我在那里使用Any,Entity 正试图将我的AccommPropertyTags 属性转换为 SQL 并且不能,因为它不是表架构的一部分。
我真的被困在这里,还是有一种很酷的方法可以解决这个烦人的错误?
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-3 entity-framework entity-framework-4.1