For some reason the code below gets this error:
An exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll but was not handled in user code
Additional information: LINQ to Entities does not recognize the method 'System.Linq.IQueryable
1[DansBlog.Domain.BlogEntities.Post] Retrieve(System.Linq.Expressions.Expression1[System.Func`2[DansBlog.Domain.BlogEntities.Post,System.Boolean]])' method, and this method cannot be translated into a store expression.
Code:
var blogRepository = this.repositoryFactory.Create<Blog>(unitOfWork);
var userRepository = this.repositoryFactory.Create<User>(unitOfWork);
var postRepository = this.repositoryFactory.Create<Post>(unitOfWork);
var allResult = blogRepository.Retrieve().Join(
userRepository.Retrieve(),
b => b.UserId,
u => u.Id,
(blog, user) => new GUI.Models.Blogging.Blog()
{
Id = blog.Id,
Content = blog.Content,
Title = blog.Title,
DateAdded = blog.DateAdded,
User = new GUI.Models.Blogging.User()
{
UserId = user.Id,
FirstName = user.FirstName,
LastName = user.LastName,
Email = user.Email,
UserName = user.UserName
},
Posts = postRepository.Retrieve(p => p.BlogId.Equals(blog.Id)).Join(
userRepository.Retrieve(),
p => p.UserId,
u => u.Id,
(post, postUser) => new GUI.Models.Blogging.Post()
{
Content = post.Content,
DateAdded = post.DateAdded,
Id = post.Id,
User = new GUI.Models.Blogging.User()
{
UserId = postUser.Id,
UserName = postUser.UserName,
FirstName = postUser.FirstName,
LastName = postUser.LastName,
Email = postUser.Email
}})});
Retrieveinto valid SQL. You have to come up with a different statement that can be converted. - jamesSampica