public IEnumerable<Models.Comment> GetUserComments()
{
return List<Comment>
{
new Comment
{
CommentFor = "ee",
DateAdded = DateTime.Now,
CommentText = "aaaa",
Location = new Location
{
Name = "Location Name",
Country = new Country
{
Name="Israel"
},
State=new State { Name="TelAviv" }
}
}
};
}
你能帮我纠正Linq查询吗?实体框架4.0与Linq
我需要使用实体框架4.
我不喜欢这个
public IEnumerable<Models.Comment> GetUserComments()
{
var comment = (from u in context.Comments
where u.UserID == userId
select new Comment
{
//Location = context.Locations.FirstOrDefault(x => x.locationid == u.LocationID).name,
Location = (from l in context.Locations
where l.LocationID == u.LocationID
select new Location
{
Name = l.Name,
State = (
from s in context.States
where (s.StateID == l.StateID)
select new State { Name = s.Name }
).FirstOrDefault()
}
).FirstOrDefault(),
CommentFor = "bs",
DateAdded = u.DateAdded,
CommentText = u.CommentText
}
).ToList();
}
喜欢把自己的错误采取从数据库值:
实体或复杂类型“CGWeb.Models.Repositories .Comment'不能在LINQ to Entities查询中构造。
请告诉我,我的错误,我做了
并请花一些时间来正确地格式化代码(见我的更新)。 – Steven