我想将SqlCacheDependency添加到我的应用程序.因此,我决定创建小型tesp项目并面临困难.我使用MSSQL 2008.我使用表格行创建新的数据库并添加了几行.我执行了:
ALTER DATABASE ForTest SET ENABLE_BROKER
Run Code Online (Sandbox Code Playgroud)
在managmeng工作室.
Aspx页面:
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Cache["Lines"] == null)
{
string connectionString =
WebConfigurationManager.ConnectionStrings["ForTest"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);
string query = "SELECT dbo.Lines.Id, dbo.Lines.Value FROM dbo.Lines";
SqlCommand cmd = new SqlCommand(query, con);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds, "Lines");
SqlCacheDependency empDependency = new SqlCacheDependency(cmd);
Cache.Insert("Lines", ds, empDependency);
}
}
}
protected void btnResult_OnClick(object …Run Code Online (Sandbox Code Playgroud) 嗨,
我正试图找到如何改进此代码的方法.我想从CreateAttributes方法中删除"if"语句.如果此属性满足某些条件,则此方法的主要思想是将属性添加到列表
internal class FildMap
{
public string ExactTargetFild { get; set; }
public string DbFild { get; set; }
public Type Type { get; set; }
}
internal static class FildMapProcessor
{
private static readonly List<FildMap> Map = new List<FildMap>();
static FildMapProcessor()
{
if(Map.Count == 0)
{
Map.Add(new FildMap {ExactTargetFild = "Address 1", DbFild = "Address1", Type = typeof (string)});
Map.Add(new FildMap { ExactTargetFild = "Date of birth", DbFild = "DateOfBirth", Type = typeof(DateTime) });
Map.Add(new FildMap { ExactTargetFild …Run Code Online (Sandbox Code Playgroud)