我正在从一个表中获取一个项目并插入到具有相同表结构的另一个表中如何使用LINQ
to entity in C#
?
public static void GetInfillIDAndInsertIntoInfillPO(int infillID)
{
Entities db = new Entities();
List<Infill> infillitem = (from c in db.Infills
where (c.InfillID == infillID)
select c).ToList();
List<InfillPO> infillPO = new List<InfillPO>();
db.InfillPOes.Add(infillitem);
}
这里Infill
并InfillPO
具有相同的表结构。只是InfillPO
不包含Primary key
。现在,我只想插入InfillPO
表中的记录。
我也通过铸造尝试过。但不会工作。
public static void GetInfillIDAndInsertIntoInfillPO(int infillID)
{
XtremeProcurementEntities db = new XtremeProcurementEntities();
Infill infillitem = (from c in db.Infills
where (c.InfillID == infillID)
select c).FirstOrDefault();
InfillPO infillPO = new InfillPO();
db.InfillPOes.Add((infillPO)infillitem);
}
帮助表示赞赏!