Linq Update SubmitChanges()-不更新
使用此代码,我的数据库中没有任何更改。 当运行上述代码时,不再创建新条目,也不会更新条目Linq Update SubmitChanges()-不更新,linq,linq-to-sql,Linq,Linq To Sql,使用此代码,我的数据库中没有任何更改。 当运行上述代码时,不再创建新条目,也不会更新条目 public void UpdateCallback(callback cb_) { callback call = context.callbacks.Single(c => c.callbackID == cb_.callbackID); //call.callbackID = cb_.callbackID; call.st
public void UpdateCallback(callback cb_)
{
callback call = context.callbacks.Single(c => c.callbackID == cb_.callbackID);
//call.callbackID = cb_.callbackID;
call.status = cb_.status;
call.contactName = cb_.contactName;
call.company = cb_.company;
call.phone = cb_.phone;
call.calledDate = cb_.calledDate;
call.callback1 = cb_.callback1;
call.notes = cb_.notes;
try
{
context.SubmitChanges();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
没有什么东西会立即向我扑来。我发现使用DataContext的Log属性查看正在生成的SQL非常有用 看 然后,您可以使用下面的代码在调试时将SQL输出到VisualStudio调试窗口
/// <summary>
/// Implementation of a <see cref="TextWriter"/> that outputs to the debug window
/// </summary>
public class DebugTextWriter : TextWriter
{
public override void Write(char[] buffer, int index, int count)
{
System.Diagnostics.Debug.Write(new string(buffer, index, count));
}
public override void Write(string value)
{
System.Diagnostics.Debug.Write(value);
}
public override Encoding Encoding
{
get { return System.Text.Encoding.Default; }
}
}
//
///输出到调试窗口的
///
公共类DebugTextWriter:TextWriter
{
公共重写无效写入(字符[]缓冲区、整数索引、整数计数)
{
System.Diagnostics.Debug.Write(新字符串(缓冲区、索引、计数));
}
公共重写无效写入(字符串值)
{
系统.诊断.调试.写入(值);
}
公共覆盖编码
{
获取{return System.Text.Encoding.Default;}
}
}
没有什么东西会立即向我扑来。我发现使用DataContext的Log属性查看正在生成的SQL非常有用
看
然后,您可以使用下面的代码在调试时将SQL输出到VisualStudio调试窗口
/// <summary>
/// Implementation of a <see cref="TextWriter"/> that outputs to the debug window
/// </summary>
public class DebugTextWriter : TextWriter
{
public override void Write(char[] buffer, int index, int count)
{
System.Diagnostics.Debug.Write(new string(buffer, index, count));
}
public override void Write(string value)
{
System.Diagnostics.Debug.Write(value);
}
public override Encoding Encoding
{
get { return System.Text.Encoding.Default; }
}
}
//
///输出到调试窗口的
///
公共类DebugTextWriter:TextWriter
{
公共重写无效写入(字符[]缓冲区、整数索引、整数计数)
{
System.Diagnostics.Debug.Write(新字符串(缓冲区、索引、计数));
}
公共重写无效写入(字符串值)
{
系统.诊断.调试.写入(值);
}
公共覆盖编码
{
获取{return System.Text.Encoding.Default;}
}
}
这与您的类似
在他的例子中,更新不起作用,因为表没有主键
您是否已验证CallbackId在数据库中定义为PK?这与您的类似
在他的例子中,更新不起作用,因为表没有主键
您是否验证了CallbackId在数据库中定义为PK?我也遇到了这个问题,原因也是如此。为清楚起见,这里重要的不是数据库中是否存在主键,而是一个或多个唯一标识记录的列是否在Linq to SQL设计器中标记为主键。换句话说,即使数据库中没有PK,将逻辑上可以充当PK的列标记为主键就足够了。。。你可以在designer中这样做吗?阿格!我也遇到了这个问题,原因也是如此。为清楚起见,这里重要的不是数据库中是否存在主键,而是一个或多个唯一标识记录的列是否在Linq to SQL设计器中标记为主键。换句话说,即使数据库中没有PK,将逻辑上可以充当PK的列标记为主键就足够了。。。你可以在designer中这样做吗?阿格!