我有一个SQL查询,想要将其翻译成Entity Framework。
我需要在Entity中进行一次运行插入多行,就像这个查询所做的那样。
INSERT INTO dbo.tbllistDepartment
(
department_sys_id,
department,
status,
client_sys_id,
lang_sys_id
)
SELECT @siDepartmentSysId,@siDepartment, @iiStatus,
@siClientSysId, lang_sys_id
FROM tblLanguageSettings
WHERE lang_sys_id <> 'Admin001'
我尝试过这个方法,但它只插入了一行数据。
public static void Insert(string langSysId, string clientSysId,string name, int status)
{
Crs2Model context = new Crs2Model();
string SysId = MyLibrary.StringCreator.GetSysId();
tblListDepartment deptObj = new tblListDepartment()
{
department_sys_id = SysId,
client_sys_id = clientSysId,
lang_sys_id=langSysId,
department=name,
status=status
};
context.tblListDepartments.Add(deptObj);
context.SaveChanges();
}