我正在为我的 C# 项目寻找 ORM。我试过 ADO.net 但我不太明白

我基于现有的数据库在我的项目中添加了一个新的 ADO.NET ORM 对象。我能够创建一个新对象,但我不太明白如何在数据库中插入我的新对象并获取从中生成的 ID。

从链接中显示的示例中,我只是不明白他们的TestDBEntities类是什么

我也愿意接受任何基于经验的 ORM 建议!谢谢!

http://img3.mukewang.com/61a3515d0001992718740572.jpg

    public static void Insert_Demande_Willy(string ModelPath)

    {

        using (TestDBEntities ctx = new TestDBEntities())

        {

            Model.CreateDessin newDemande = new CreateDessin()

            {

                DateProduite = DateTime.Now,

                GenerateBom = Willy.Properties.Settings.Default.GenerateBom.ToString(),

                MailAdress = Willy.Properties.Settings.Default.Email,

                NotifyRBRE = Willy.Properties.Settings.Default.Wilma_RBRE.ToString(),

                NotifyRBTK = Willy.Properties.Settings.Default.Wilma_RBTK.ToString(),

                NotifyTLS = Willy.Properties.Settings.Default.Wilma_TLS.ToString(),

                NotifyTQ = Willy.Properties.Settings.Default.Wilma_TQ.ToString(),

                PathDessin = ModelPath,

                SendingComputer = Environment.MachineName,

                UserName = Environment.UserName

            };


            Insert_Demande_Willy_DTL(newDe)


        }


    }


    /// <summary>

    /// Importer Statuts enumeration

    /// Setter priorité

    /// NoECO juste quand check? 

    /// IF DEV TESTED BY 

    /// </summary>

    /// <param name="ID"></param>

    private static void Insert_Demande_Willy_DTL(int ID)

    {

        Model.CreateDessinDTL newDemandeDTL = new CreateDessinDTL()

        {

            ConfigName = "",

            CreatePDF = Willy.Properties.Settings.Default.GeneratePDF.ToString(),

            C_ID = ID,

            NoECO = Willy.Properties.Settings.Default.EcoName,

            Priority = 2,

            Statut = "Willy2",



        };

    }


杨__羊羊
浏览 194回答 2
2回答

郎朗坤

同意楼上的评论员。EF6 非常好。另外——我对 EF6 很陌生,但我相信您可以将它设置为在现有数据库上以代码优先的方式工作,因为您可以使用 EFPowerTools 生成模型,然后进行任何更改您的代码将在您的数据库中自动更新。https://msdn.microsoft.com/en-us/library/jj200620(v=vs.113).aspx

慕慕森

我以某种方式找到了使这件事起作用的方法。不幸的是,某些对象的某些成员不会与 Intellisence 一起显示。&nbsp; &nbsp; /// <summary>&nbsp; &nbsp; /// Setter priorité&nbsp; &nbsp; /// NoECO juste quand check?&nbsp;&nbsp; &nbsp; /// </summary>&nbsp; &nbsp; /// <param name="ID"></param>&nbsp; &nbsp; private static void Insert_Demande_Willy_DTL(int ID)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DemoInfo_IndusEntities context = new DemoInfo_IndusEntities();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context.CreateDessinDTL.Add(new CreateDessinDTL_Demo()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ConfigName = "",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; C_ID = ID,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NoECO = Willy.Properties.Settings.Default.EcoName,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Priority = 2,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Statut = AppConfig.Controller.Statuts.Willy.Willy2,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TestedBy = Environment.UserName&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //CreatePDF = Willy.Properties.Settings.Default.GeneratePDF.ToString(),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context.SaveChanges();&nbsp; &nbsp; &nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP