tug*_*erk 5 c# asp.net-mvc entity-framework entity-framework-4.1 asp.net-mvc-3
我被困在我的ASP.NET MVC 3应用程序的某个地方.这是我得到的错误:
LINQ to Entities不支持指定的类型成员'AccommPropertyTags'.仅支持初始值设定项,实体成员和实体导航属性.
我已经找到了如何在以下文章中解决这个问题:
但我的有点奇怪.
这是我的实体的部分类之一:
[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; }
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,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);
}
Run Code Online (Sandbox Code Playgroud)
由于我在Any
那里使用的事实,实体正在尝试将我的AccommPropertyTags
属性转换为SQL而不能,因为它不是表模式的一部分.
我真的被困在这里还是有一种很酷的方式来打败这个恼人的错误?
Era*_*nga 10
您的问题与您链接的问题类似.model.ToList()
使用前请致电Where
.这将强制EF实现实体,然后在内存中应用剩余的过滤.
public ViewResult Tag(string tag) {
var _rawTag = HttpUtility.UrlDecode(tag);
ViewBag.Tag = _rawTag;
var model = _accommpropertyrepo.GetAllAccommPropertiesFullWebIgnoringApprovalStatus();
var result = model.ToList().Where(
x => x.AccommPropertyTags.Any(
y => y == _rawTag
)
);
return View(result);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8969 次 |
最近记录: |