[英]Add element from list to database by class in c# using LINQ
I created a data model using EntityFramework and with the help of appropriate queries I get the data from the database. 我使用EntityFramework创建了数据模型,并借助适当的查询从数据库中获取数据。 I would like the button to be able to delete all documents that will be marked as WZ (document number).
我希望该按钮能够删除将被标记为WZ(文档编号)的所有文档。 I created the HistoryWZ class which will be a new table storing the story and I would like to use the LINQ query to extract data from one table, pass it to the second table and delete it from the first table.
我创建了HistoryWZ类,它将是一个存储故事的新表,我想使用LINQ查询从一个表中提取数据,将其传递给第二个表,然后从第一个表中删除它。
Using LINQ i got list of data: 使用LINQ,我得到了数据列表:
EntitiesSito ent = new EntitiesSito();
dynamic wkaa = datagridview.SelectedItem;
string actwuzetka = wkaa.WZ.ToString();
var skad = (from d in ent.WZ_DWS_SITO
where d.WZ == actwuzetka
select new
{
d.WZ,
d.KUNNR
}).ToList();
I would like to use the created class to pass data to the table using LINQ ofc. 我想使用创建的类使用LINQ ofc将数据传递到表。
My HistoryWZ class : 我的HistoryWZ课:
ublic class HistoryWZ
{
public string NrWZ { get; set; }
public string ODBIORCA { get; set; }
public string DataWZ { get; set; }
public string INDEKS { get; set; }
public string MATERIAL { get; set; }
public string PARTIA { get; set; }
public decimal ILOSC { get; set; }
public string NAZWA_MATERIALU { get; set; }
public string PRZYCZYNA { get; set; }
public decimal CENAMIN{ get; set; }
public decimal CENASPRZ { get; set; }
public decimal VPRS { get; set; }
public decimal MARZA { get; set; }
public string user = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
}
Are Table A
and Table B
of the same structure? Table A
和Table B
是否具有相同的结构? If so, it sounds like you've got a problem at the database schema level as its not properly normalised. 如果是这样,听起来好像您在数据库架构级别遇到了问题,因为它没有正确规范化。 If they are not, then:
如果不是,则:
DbContext
. DbContext
创建一个新事务。 Table A
and place in Table B
(We will call this Table A Object
). Table A
查询要提取的项目并将其放在Table B
(我们称此Table A Object
)。 Table B Object
. Table B Object
。 Table B Object
with the data from the Table A Object
. Table B Object
中的数据填充Table B Object
Table A Object
。 Table B Object
to the context with DbContext.Add(TableBObject)
DbContext.Add(TableBObject)
将Table B Object
添加到上下文中 DbContext.Remove(TableAObject)
and commit the transaction DbContext.Remove(TableAObject)
并提交事务
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.