c# - 使用 recordType 的对象更新 Linq2Sql 中的记录

标签 c# .net linq-to-sql

以下简化代码不起作用(因为它将检索到的对象引用设置为参数),但它显示了我想要执行的操作

 public bool updateEvent(clubEvent newEvent)
    {
        TNightCon tCon = new TNightCon();
        clubEvent cEv = (from cEvent in tCon.clubEvents
                         where cEvent.EventID == newEvent.EventID
                         select cEvent).First();

        // Won't work, but do I have to set all the fields manually?
        cEv = newEvent;
        tCon.SubmitChanges();
        return true;
    }

最佳答案

或者,交替地,

  tCon.ClubEvents.DeleteOnSubmit(cEv);
  tCon.CLubEvents.InsertOnSubmit(newEvent);
  tCon.SubmitChanges();

关于c# - 使用 recordType 的对象更新 Linq2Sql 中的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/752303/

相关文章:

c# - UIImagePickerController 出现 "Attempt to present Xamarin_Forms_Platform_iOS_ModalWrapper whose view is not in the window hierarchy"错误

c# - 查找本地服务器的 IP 地址

c# - 在 C# 中对数据进行分组和进行聚合计算

c# - Linq 2 Sql 使用 'Like' 将本地序列与查询进行比较 - 最有效的方法

c# - 身份验证在 IIS8.5 中安装的 Wordpress 博客的子目录中不起作用

c# - C#.Net Close应用程序超出内存使用量

c# - 使用 System.Xml.Serialization.XmlSerializer 反序列化有效 xml 文件时存在差异

c# - IIS 文件锁定 - 该进程无法访问该文件,因为它正被另一个进程使用

c# - LINQ 多对多交集

c# - 在 linq 表映射中将多个表分配给单个类