私は次のエンティティクラスを持っています:
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はPostクラスについて何も知りません。また、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:タイプ'Facebook.Business.Domain.Accounts.UserAccount'の定数値を作成できません。このコンテキストでは、プリミティブ型または列挙型のみがサポートされています。
...そしてスタック..。
System.Data.Objects.ELinq.ExpressionConverter.ConstantTranslator.TypedTranslate(ExpressionConverter parent、ConstantExpression linq)at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)atSystem.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)atSystem.Data.Objects。 ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent、MethodCallExpression call、ref DbExpression source、ref DbExpressionBinding sourceBinding、ref DbExpression lambda)atSystem.Data.Objects.ELinq。System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent、MethodCallExpression linq)at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpressのExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent、MethodCallExpression call) )at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent、MethodCallExpression linq)at System.Data.at System.Data.Objects.ELinq.ExpressionConverter.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent、MethodCallExpression call)at System.Data System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(NullableSystem.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent、MethodCallExpression linq)at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)atSystem.Data。 Object.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent、MethodCallExpression call)at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent、MethodCallExpression linq)atSystem.Data.Objects.ELinq。 System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(NullableSystem.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent、MethodCallExpression linq)at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)atSystem.Data。 Object.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent、MethodCallExpression call)at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent、MethodCallExpression linq)atSystem.Data.Objects.ELinq。 System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(NullableExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent、MethodCallExpression linq)at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionCon )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(NullableExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent、MethodCallExpression linq)at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionCon )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(NullableObject.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent、MethodCallExpression call)at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent、MethodCallExpression linq)atSystem.Data.Objects.ELinq。 System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(NullableObject.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent、MethodCallExpression call)at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent、MethodCallExpression linq)atSystem.Data.Objects.ELinq。 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:
これまでのところ、誰かがここで何が起こっているのか説明できますか?クエリにナビゲーションプロパティを使用するべきではないようです。
誰かが私に別の解決策を与えることができますか?
前もって感謝します。