나는이 오류를 받고 있어요 : 내가해야 할 노력은 무엇엔티티 프레임 워크 객체에 대한 사용자 정의 비교 (이진 연산자 Equal에 대한 정의)를 int에 쓰려면 어떻게해야합니까?
ex = {"The binary operator Equal is not defined for the types 'MySite.Domain.DomainModel.EntityFramework.NickName' and 'System.Int32'."}
는 선택을했다 모든 곳 NickNameId = someIntPassedIn
... 문제는 NickNameId이는 someIntPassedIn
에 비교 그렇게 할 때, 외래 키 점이다 NickNameId
은 NickNameId
이 참조하는 전체 NickName
개체를 가져 와서 int를 해당 개체와 비교하려고합니다. 나는이 두 개체
또는
을 비교 평등 이진 연산자를 정의 할 수 있습니다 어떻게 그것을 별명 개체의 ID로 INT 비교 할 수 있도록 여기에 솔루션을 필요로... 그래서
A)
B) 어떻게 전체 개체 대신 ID와 직접 비교할 수 있습니까?
public IList<E> SelectAllByKey(string columnName, string key)
{
KeyProperty = columnName;
int id;
Expression rightExpr = null;
if (int.TryParse(key, out id))
{
rightExpr = Expression.Constant(id);
}
else
{
rightExpr = Expression.Constant(key);
}
// First we define the parameter that we are going to use the clause.
var xParam = Expression.Parameter(typeof(E), typeof(E).Name);
MemberExpression leftExpr = MemberExpression.Property(xParam, this._KeyProperty);
int temp;
BinaryExpression binaryExpr = MemberExpression.Equal(leftExpr, rightExpr);
//Create Lambda Expression for the selection
Expression<Func<E, bool>> lambdaExpr = Expression.Lambda<Func<E, bool>>(binaryExpr, new ParameterExpression[] { xParam });
//Searching ....
IList<E> resultCollection = ((IRepository<E, C>)this).SelectAll(new Specification<E>(lambdaExpr));
if (null != resultCollection && resultCollection.Count() > 0)
{
//return valid single result
return resultCollection;
}//end if
return null;
}
당신이 더 필요하면 알려주세요 ("1"나는 "NickNameId"전달과)
가 :
당신은 여기를 읽을 필요하지 않지만 그것이 도움 넣다 SelectAllByKey 방법입니다 정보.
감사합니다,
매트
당신은 신입니다! 정말 고맙습니다! – Matt