Reputation: 8783
I've faced a problem that is:
An exception of type 'System.ArgumentException' occurred in EntityFramework.dll but was not handled in user code
Additional information: The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.
How can I solve it?
This problem happen in FindAll
method
articleViewModel.AttachmentFiles = AttachmentFileBLL.Instance.FindAll(c => c.ArticleId == articleViewModel.Id).ToList();
FindAll method:
public virtual IQueryable<TModel> FindAll(params Expression<Func<TModel, object>>[] includeProperties)
{
IQueryable<TModel> items = RepositoryContainer<TRepository>().FindAll();
if (includeProperties != null)
{
foreach (var includeProperty in includeProperties)
{
items = items.Include(includeProperty); // Problem occurred here!
}
}
return items;
}
public virtual int? ArticleId { get; set; }
public virtual int Id { get; set; }
Upvotes: 2
Views: 10900
Reputation: 18685
You are passing an invalid argument to the DbExtensions.Include Method because it requires
A lambda expression representing the path to include.
and not a condition like you've specified:
c => c.ArticleId == articleViewModel.Id
You need to call FindAll
differently:
AttachmentFileBLL
.Instance
.FindAll(c => c.ArticleId)
.ToList();
This would specifiy the property.
But as you also need to specify a navigation property for this you need to use such a property there. I don't know what name it can have in you model but something like this perhaps:
AttachmentFileBLL
.Instance
.FindAll(c => c.Articles) // Assuming 'Articles' is a navigation property.
.ToList();
If you want to get only some items you should put the condition elsewere in some Where
that would suit your needs:
AttachmentFileBLL
.Instance
.SomeCollection
.Where(c => c.ArticleId == articleViewModel.Id)
.FindAll(c => c.Articles)
.ToList();
Upvotes: 1