我看到如何使用stringbuilders(SQL /实体框架)构建字符串;如何使连接字符串在DbContext中使用?
示例上下文:
public class pophistoryDBContext : DbContext
{
public DbSet<pophistory> histories {get;set}
}
public class pophistoryrepository: Ihistoryrepository
{
private pophistoryDBContext context = new pophistoryDBContext();
public IQueryable<pophistory> histories{
get {return context.histories;}
}
}
控制器中的示例用法:
public class HistoryController : Controller
{
private Ihistoryrepository repository = new pophistoryrepository();
var histories = from h in repository.histories where (h.modifyTimestamp > today) select h;
if (!String.IsNullOrEmpty(SearchString))
{
histories = histories.Where(h => h.dn.ToUpper().Contains(SearchString.ToUpper()));
}
谢谢