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" }
}
}
};
}
Pouvez-vous m'aider à corriger la requête Linq pour cela?Entity Framework 4.0 avec Linq
Je dois prendre la valeur de base de données en utilisant Entity Framework 4.
Je l'ai fait comme ça
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();
}
obtenir erreur comme:
Le type d'entité ou complexe « de CGWeb.Models.Repositories "Commentaire" ne peut pas être construit dans une requête LINQ to Entities.
S'il vous plaît me dire où mon erreur je l'avais fait
Et s'il vous plaît prendre un certain temps pour formater correctement votre code (voir ma mise à jour). – Steven