[英]Adding list elements to the database using LINQ and Entity Framework
When creating an application, I came across a problem. 在创建应用程序时,我遇到了一个问题。 I have created a data model and there are 2 classes among them (there are more but in the example it's about these 2)
我创建了一个数据模型,其中有2个类(还有更多类,但在示例中大约是这2个类)
The first class concerns WZ documents: 第一类涉及WZ文档:
public partial class WZ_DWS_SITO
{
public string WZ { get; set; }
public string WZ_DATA { get; set; }
public string WZ_CZAS { get; set; }
public string WZ_POZYCJA { get; set; }
public string MATERIAL { get; set; }
public string PARTIA { get; set; }
public string ZAKLAD { get; set; }
public string SKLAD { get; set; }
public decimal WZ_ILOSC { get; set; }
public string ZLECENIE { get; set; }
public string ZLECENIE_DATA_UTWORZENIA { get; set; }
public string KUNNR { get; set; }
public string ZLECENIE_POZYCJA { get; set; }
public decimal ZLECENIE_CENA_NETTO { get; set; }
public decimal ZLECENIE_ILOSC { get; set; }
public decimal ZLECENIE_NETTO { get; set; }
public decimal ZLECENIE_KOSZT { get; set; }
public string WWW { get; set; }
public Nullable<decimal> ZLECENIE_CENA_ZAKUPU { get; set; }
public Nullable<decimal> ZLECENIE_ZYSK { get; set; }
public Nullable<decimal> ZLECENIE_MARZA { get; set; }
public string VE { get; set; }
public Nullable<decimal> WZ_KOSZT { get; set; }
public Nullable<decimal> WZ_NETTO { get; set; }
public Nullable<decimal> WZ_ZYSK { get; set; }
public Nullable<decimal> WZ_CALA_NETTO { get; set; }
public Nullable<decimal> ATP_SKLAD { get; set; }
public Nullable<decimal> ATP_ZAKLAD { get; set; }
public string DATA_WYCENY { get; set; }
public Nullable<decimal> CENA_MINIMALNA { get; set; }
public Nullable<decimal> WZ_ILOSC_NA_WZ { get; set; }
public Nullable<decimal> ILOSC_60DNI_ABC_5PROCENT { get; set; }
public string PRZYCZYNA { get; set; }
public string STATUS { get; set; }
public string L0 { get; set; }
public string L1 { get; set; }
public string L2 { get; set; }
public string NAZWA_KLIENTA { get; set; }
public Nullable<int> INDEKS { get; set; }
public string NAZWA_MATERIALU { get; set; }
public string PH { get; set; }
public Nullable<decimal> MARZA_ZLECENIE_ALL { get; set; }
}
The second one collects the history of accepted documents: 第二个收集接受文档的历史记录:
public class HISTORYWZ
{
public string NrWZ { get; set; }
public string ODBIORCA { get; set; }
public string DATAWZ { get; set; }
public int 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; }
}
Chciałbym wyciągając pojedyńczą WZ (która może mieć kilka pozycji) móc wrzucić ją do historii ale tylko elementy które są mi potrzebne. ChzłbymwyciągającpojedyńcząWZ(któramożemiećkilka pozycji)mócwrzucićjądo historii ale tylko elementyktóresąmi potrzebne。 Wyciągnąłem sobie elementy za pomocą LINQ :
Wyciągnąłemsobie elementy zapomocą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
).ToList();
And I would like to add these elements to the database by assigning that WZ from the WZ_DWS_SITO class corresponds to the number of the WZ from the HistoryWZ class and so on. 并且我想通过将WZ_DWS_SITO类中的WZ分配给HistoryHZ类中的WZ编号来将这些元素添加到数据库中,依此类推。 Then I want to delete the records from the database, but I've already covered myself.
然后,我想从数据库中删除记录,但是我已经介绍了自己。
var skad = (from d in ent.WZ_DWS_SITO
where d.WZ == actwuzetka
select new HISTORYWZ()
{
//NrWZ = d.WZ_ ,
//ODBIORCA = d.ODBIORCA,
//DATAWZ = d.DATAWZ,
INDEKS = d.INDEKS.Value,
MATERIAL = d.MATERIAL,
PARTIA = d.PARTIA,
ILOSC = d.WZ_ILOSC,
PRZYCZYNA = d.PRZYCZYNA,
NAZWA_MATERIALU = d.NAZWA_MATERIALU,
//CENAMIN = d.WZ_ICENAMIN,
//CENASPRZ = d.WZ_ICENASPRZ,
//VPRS = d.WZ_VPRS,
//MARZA = d.WZ_MARZA,
}
).ToList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.