Simple Application of ADO. NET Entity Framework extensions

Source: Internet
Author: User
I. Scenarios

If your project contains stored procedures that return multiple result sets.

If your project is to share transactions with ADO. net in the old project.

If you want to dynamically create a database table.

However, you still want to use Entity Framework. Let's continue.

Ii. Ado. NET Entity Framework extensions ()

1. Reference The efextensions. dll file.

2. AddUsingMicrosoft. Data. extensions; statement.

3. efextensions execute the T-SQL statement
 
Public void executesql (string SQL) {using (dbentities DB = new dbentities () {using (dB. connection. createconnectionscope () {var cmd = dB. createstorecommand ("Update orders set freight = 8 where orderid = 10292", commandtype. text); cmd. executenonquery ();}}}
Iv. efextensions

 

Public dataset executeprocedure () {using (dbentities DB = new dbentities () {var cmd = dB. createstorecommand ("custordersorders", commandtype. storedprocedure, new sqlparameter ("customerid", "alfki"); sqldataadapter da = new sqldataadapter (CMD as sqlcommand); dataset DS = new dataset (); DA. fill (DS); Return DS ;}}
5. efextensions execute the T-SQL statement to obtain the entity set
 
Public ienumerable <orders> getsql () {using (dbentities DB = new dbentities () {return dB. createstorecommand ("select * from orders", commandtype. text ). materialize <orders> ();}}
6. Allow EF to share transactions with ADO. net
Public void usesametran () {using (var tran = new transactionscope (transactionscospontion. required) {using (dbentities DB = new dbentities () {using (dB. connection. createconnectionscope () {orders order = dB. orders. firstordefault (O => O. orderid = 10291); Order. freight = 7; dB. savechanges (); var cmd = dB. createstorecommand ("Update orders set freight = 8 where orderid = 10292", commandtype. text); cmd. executenonquery (); Tran. complete ();}}}}
7. view the T-SQL Statement of LINQ
VaR q = from P in context. products where p. productname. startswith ("foo") select P; // before string commandtext = (objectquery <product>) q ). totracestring (); // after string commandtext = Q. totracestring ();
VIII. Conclusion

Using EF for projects is also a problem that is easy to solve. Entity Framework extensions has been solved for us.

There are some other applications in the downloaded instance. You can explore the things later.

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.