는 다음과 같은 엔티티 클래스가 I :탐색 속성으로 쿼리하는 중 오류가 발생 했습니까?
using System;
using System.Collections.Generic;
using Facebook.Business.Domain.Accounts;
namespace Business.Domain.Posts
{
/// <summary>
/// This class defines a post.
/// </summary>
public class Post : Entity<Post>
{
#region Fields
private UserAccount _author;
private UserAccount _owner;
private DateTime _date;
private string _text;
private IList<Comment> _comments;
#endregion
#region Ctors
protected Post()
{
}
public Post(UserAccount author,
UserAccount owner,
DateTime date,
string text)
{
_author = author;
_owner = owner;
_date = date;
_text = text;
_comments = new List<Comment>();
}
#endregion
/// <summary>
/// Gets or sets the account that writes and sends the current post.
/// </summary>
public virtual UserAccount Author
{
get { return _author; }
protected set { _author = value; }
}
/// <summary>
/// Gets or sets the datetime of the current post.
/// </summary>
public virtual DateTime Date
{
get { return _date; }
protected set { _date = value; }
}
/// <summary>
/// Gets or sets the text of the current post.
/// </summary>
public virtual string Text
{
get { return _text; }
protected set { _text = value; }
}
/// <summary>
/// Gets or sets the user that receives the current post.
/// </summary>
public virtual UserAccount Owner
{
get { return _owner; }
protected set { _owner = value; }
}
/// <summary>
/// Gets or sets the comments for the current post.
/// </summary>
public virtual IList<Comment> Comments
{
get { return _comments; }
protected set { _comments = value; }
}
public void Add(Comment comment)
{
_comments.Add(comment);
}
#region Implementation of ICommentable
IEnumerable<Comment> ICommentable.Comments { get { return Comments; } }
#endregion
}
}
클래스 UserAccount는 포스트 클래스에 대해 아무것도 몰라를 UserAccount 또한 엔티티입니다.
는 나는 각각의 저장소 클래스에서이 메소드를 구현해야합니다
/// <summary>
/// Retrieve the posts that were posted by a given account: <paramrefname="author"/>
/// </summary>
/// <param name="author">An account.</param>
/// <returns>The posts that were posted by <paramref name="author"/></returns>
public IQueryable<Post> FindPostsFrom(UserAccount author)
{
ContractUtil.NotNull(author);
return Set.Where(post => post.Author.Equals(author));
}
을하지만 난 내가 다음과 같은 오류를 얻을 테스트를 실행하면
System.NotSupportedException : Unable to create a constant value of type 'Facebook.Business.Domain.Accounts.UserAccount'. Only primitive types or enumeration types are supported in this context.
... 그리고 스택. ..
at System.Data.Objects.ELinq.ExpressionConverter.ConstantTranslator.TypedTranslate(ExpressionConverter parent, ConstantExpression linq) at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) at System.Data.Objects.ELinq.ExpressionConverter.EqualsTranslator.TypedTranslate(ExpressionConverter parent, BinaryExpression linq) at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input) at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, ref DbExpression source, ref DbExpressionBinding sourceBinding, ref DbExpression lambda) at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call) at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq) at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call) at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq) at System.Data.Objects.ELinq.ExpressionConverter.Convert() at System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable
1 forMergeOption) at System.Data.Objects.ObjectQuery
1.GetResults(Nullable1 forMergeOption) at System.Data.Objects.ObjectQuery
1.System.Collections.Generic.IEnumerable.GetEnumerator() at System.Linq.Enumerable.First(IEnumerable1 source) at System.Linq.Queryable.First(IQueryable
1 source) at Data.EntityFramework.Tests.PostRepositoryTests.FindPostsFrom_FindingAPostGivenAnAuthor_ShouldRetrieveIt() in PostRepositoryTests.cs: line 136
지금까지 아무도 내가 무슨 일을하고 있는지 설명 할 수 있습니까? 쿼리에 탐색 속성을 사용해서는 안됩니다.
아무에게도 대안 솔루션을 제공 할 수 있습니까?
미리 감사드립니다.