实体框架相当于InsertonSubmit的 [英] Entity Framework equivalent of InsertonSubmit

查看:70
本文介绍了实体框架相当于InsertonSubmit的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有一个问题与基本相同的标题,但在我的情况有所不同。我从LINQ到SQL实体框架(我是一个小新)感动,我有,我用 InsertOnSubmit 的方法,所以我发现它是在LINQ到SQL,而不是在实体框架,任何想法



LINQ到SQL:

  dc.tblTruckDetails.InsertOnSubmit(tblInsert); 
dc.SubmitChanges();


解决方案

您不需要调用 InsertOnSubmit 在实体框架。



您可以简单地创建你想要什么新对象添加在数据库中,然后调用的SaveChanges 方法。

 实体实体=新的实体(); 

员工EMP =新员工();
emp.Name =Mairaj;

entities.Employees.Add(EMP);
entities.SaveChanges();


I know there is a question with basically the same header but is different in my case. I moved from Linq-to-SQL to Entity Framework (which I am a little new to) and I have a method where I use InsertOnSubmit, and so I found out it is in Linq-to-SQL and not in Entity Framework, any ideas?

Linq-to-SQL:

  dc.tblTruckDetails.InsertOnSubmit(tblInsert);
  dc.SubmitChanges();

解决方案

You don't need to call InsertOnSubmit in Entity Framework.

You can simply create a new object of what you want to add in database and then call SaveChanges method.

Entities entities = new Entities();

Employee emp = new Employee();
emp.Name = "Mairaj";

entities.Employees.Add(emp);
entities.SaveChanges();

这篇关于实体框架相当于InsertonSubmit的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆