简体   繁体   English

使用LINQ和Entity Framework将列表元素添加到数据库

[英]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.

相关问题 使用 Entity Framework Core 将订单列表添加到数据库中的困惑 - Confusion on adding list of orders into database using Entity Framework Core 实体框架/ Linq:有效检测数据库中是否存在所有元素 - Entity Framework / Linq: Efficiently detect if all elements exist in database 使用实体框架将 OrderDetail 添加到数据库 - Adding OrderDetail to database using Entity Framework 使用实体框架 LINQ 有效检查数据库中是否存在记录 - Efficiently check if record exists in database using Entity framework LINQ 使用带有实体框架和 LINQ 的单个数据库查询搜索多个字符串 - Searching for multiple strings using single database query with entity framework and LINQ 使用实体框架linq从数据库结果中获取项目 - Get item from database result by using entity framework linq 使用实体框架LINQ将唯一主键插入数据库 - Insert Unique Primary Key into Database using Entity-Framework LINQ 无法使用实体框架从linq查询转换列表 - Cannot convert List from linq query using Entity Framework 给出多个清单 <int> 在实体框架中使用linq键入条件 - Giving Multiple List<int> type criteria by using linq in Entity Framework 使用LINQ或Entity Framework将数据分割为列出对象C# - Split datatable to list object C# using LINQ or Entity Framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM