Insert/Delete POCO

by Alexey Shirshov May 07, 2009 15:26

So what about creating new instances of POCO in DBMS or deleting it? No problem. You need to create and save it.

        static void Main(string[] args)
        {
            //create new instance
            Sales.SalesTerritory t = new exam1sharp.Sales.SalesTerritory()
            {
                Name = "China",
                CountryRegionCode = "CH",
                Group = "Asia",
                SalesYTD = 100,
                SalesLastYear = 100,
                ModifiedDate = DateTime.Now
            };

            //save new instance
            using (ModificationsTracker mt = new ModificationsTracker(exam1sharp.Properties.Settings.Default.connString))
            {
                mt.Add(t);
                mt.AcceptModifications();
            }

            Console.WriteLine("New SalesTerritory id = {0}", t.ID);

            //delete created instance
            using (ModificationsTracker mt = new ModificationsTracker(exam1sharp.Properties.Settings.Default.connString))
            {
                mt.Delete(t);
                mt.AcceptModifications();
            }
        }

Tags:

Add comment


(Will show your Gravatar icon)  

Enter the word
captcha word
(hear it spoken)


  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen | Modified by Mooglegiant

The Author

My name is Alexey Shirshov. I'm a professional developer with wide specialization. I prefer VB.NET to C#, I hate ASP.NET but there is no better than it. You can contact me by this page.