使用mvc3,我需要在运行时向sql连接字符串添加用户名/密码

时间:2013-04-05 20:21:48

标签: asp.net-mvc-3 connection-string

我看到如何使用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()));
        }

谢谢

0 个答案:

没有答案