Your question isn't very clear, but if you mean that You wanna do it in a generic way, then yes that is possible. You can take advantage of the Set<T>
method. For example:
public void LoadToGrid<T>(GridType grid) where T: class, new() {
grid.DataSource = dbContext.Set<T>().ToList();
}
And to customize the data fields in your grid, your can add this overload
public void LoadToGrid<T>(GridType grid, Expression<Func<T,Object>> selectExpression) where T: class, new() {
grid.DataSource = dbContext.Set<T>().Select(selectExpression).ToList();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…