----Efcontext objects Get---Singleton mode from the data slot

Source: Internet
Author: User

1 class Program2     {3         Static voidMain (string[] args)4         {5             //DbContext context = Contextfactory.getcontext ();6             //OrderInfo oi = new OrderInfo ()7             //{8             //ordertitle= "Samsung mobile"9             //};Ten             //Oi. CustomerInfo = new CustomerInfo () One             //{ A             //customername= "Chun Yuchon", -             //Customerdate=datetime.now -             //}; the             //context. Set<orderinfo> (). Add (OI); -             //context. SaveChanges (); -             //Console.WriteLine ("OK"); -             //Console.readkey (); +  -             //Test, + addcustomerinfo (); A addorderinfo (); at Save (); -Console.WriteLine ("OK"); - Console.readkey (); -  -         } -         /// <summary> in         ///  -         /// </summary> to         Private Static voidSave () +         { -DbContext context =Contextfactory.getcontext (); the context. SaveChanges (); *         } $ Panax Notoginseng         Private Static voidAddcustomerinfo () -         { theDbContext context =Contextfactory.getcontext (); +Context. Set<customerinfo> (). ADD (NewCustomerInfo () A             { theCustomerName ="Big Zhang Wei", +Customerdate =DateTime.Now -             }); $  $         } -  -         Private Static voidAddorderinfo () the         { -DbContext context =Contextfactory.getcontext ();WuyiContext. Set<orderinfo> (). ADD (NewOrderInfo () the             { -ordertitle="Seven Stars Blades", WuCustomerid=7 -             }); About         } $     } -     /// <summary> -     ///gets the class of the context object -     /// </summary> A      Public Static classcontextfactory +     { the          Public StaticDbContext getcontext () -         { $             //Gets the context object from the data slot, guaranteeing the object's single theDbContext context = CallContext.GetData ("DbContext") asDbContext; the             if(Context = =NULL) the             { the                 //when the data slot does not exist. Create a context object and put it in a data slot -Context =Neweftestentities (); inCallcontext.setdata ("DbContext", context); the             } the             returncontext; About         } the}

----Efcontext objects Get---Singleton mode from the data slot

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.