-3

I added a new ADO.NET ORM object inside my project based on an already existing database. I was able to create a new object but I don't quite understand how to insert my new object in the database and get the ID generated from it.

From the example shown in the link, I just don't understand what is their TestDBEntities Class

I am also opened to any ORM suggestion based off experience! Thanks!

enter image description here

        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",


        };
    }

Source 1 Source 2

  • 1
    If your choice in ORM is free to make I would recommend looking at a more recent release like Entity Framework 6: https://learn.microsoft.com/en-us/ef/index#pivot=entityfmwk – Lennart Stoop Aug 14 '18 at 19:36

2 Answers2

0

Agree with the above commentor. EF6 is very nice. Also--I am pretty new to EF6, but I believe that you can set it up to work in a code first way on an already existing database, as in you can use EFPowerTools to generate your models, and then any changes that you make to your code will be automatically updated in your database.

https://msdn.microsoft.com/en-us/library/jj200620(v=vs.113).aspx

Justin Le
  • 673
  • 1
  • 8
  • 24
0

I somehow found a way to make this thing work. Unfortunately, some members of some objects won't show with Intellisence.

    /// <summary>
    /// Setter priorité
    /// NoECO juste quand check? 
    /// </summary>
    /// <param name="ID"></param>
    private static void Insert_Demande_Willy_DTL(int ID)
    {
        {

            DemoInfo_IndusEntities context = new DemoInfo_IndusEntities();

            context.CreateDessinDTL.Add(new CreateDessinDTL_Demo()
            {
                ConfigName = "",
                C_ID = ID,
                NoECO = Willy.Properties.Settings.Default.EcoName,
                Priority = 2,
                Statut = AppConfig.Controller.Statuts.Willy.Willy2,
                TestedBy = Environment.UserName
                //CreatePDF = Willy.Properties.Settings.Default.GeneratePDF.ToString(),


            });

            context.SaveChanges();
        }}