我試圖做到這一點:屬性選擇和地點<T>查詢使用LINQ
public class SomeEntityClass
{
public Guid MyClassProperty {get;set;}
}
public class AnotherEntityClass
{
public Guid AnotherProperty {get;set;}
}
public T GetByProperty<T>(Guid value, Expression<Func<T, object>> selector)
{
return = Session.Query<T>().Where(x => selector == value).FirstOrDefault();
}
應該叫:
Repository.GetByProperty<SomeEntityClass>(Guid.NewGuid(), x => x.MyClassProperty);
Repository.GetByProperty<AnotherEntityClass>(Guid.NewGuid(), x => x.AnotherProperty);
,但它不工作。
任何幫助?
謝謝。
不應該''對象'是'Guid'因爲你想要一個返回'Guid'的方法嗎? –
爲什麼不使用'x => x.MyClassId == Guid.NewGuid()'? – hazzik
說「不起作用」不如說什麼不起作用(錯誤消息/示例意外結果)。 –