我有一個類擴展了System.Web.UI.WebControls.GridView控件。 我想要一個屬性,可以保存我的EF表達式以在整個控件中使用。商店Expression <Func <T, bool>>其中作爲類屬性
問題是,T沒有定義。
public sealed class NCGridView : GridView
{
private Expression<Func<T, bool>> _where;
public void LoadWhere(Expression<Func<T, bool>> where)
{
_where = where;
}
}
紅帽建議嘗試
private Expression<Func<BaseModel, bool>> _where;
public void LoadWhere<T>(Expression<Func<T, bool>> where) where T : BaseModel
{
// Cannot cast from: Expression<Func<T, bool>> to: Expression<Func<BaseModel, bool>>
_where = where;
}
嗯......什麼爲T意味着代表什麼?將存儲作爲非通用表達式足夠嗎? (在需要時將其轉換並知道) –
T是綁定到GridView的行的類型。你能在設計時知道嗎?我從來沒有聽說過一種通用控制。不,等等,看看[這個](http://stackoverflow.com/questions/1329362/c-sharp-generics-usercontrol)。 – sq33G
你能舉一個你打算如何使用表達式的例子嗎? – dtb