Simple Application of ADO. NET Entity Framework extensions)

Source: Internet
Author: User
Http://www.cnblogs.com/sorex/archive/2010/08/16/1800761.html 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 ?
123456789101112 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

 

?
123456789101112 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 ?
1234567 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 ?
1234567891011121314151617181920 Public Void Usesametran () { Using (Var tran = New Transactionscope (transactionscopeoption. 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 ?
123456789 var q = from P in context. products where p. productname. startswith ( "foo" ) select P; // before string commandtext = (objectquery ) 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.

Http://www.cnblogs.com/sorex/archive/2010/08/16/1800761.htmlI. 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 ?
123456789101112 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

 

?
123456789101112 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 ?
1234567 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 ?
1234567891011121314151617181920 Public Void Usesametran () { Using (Var tran = New Transactionscope (transactionscopeoption. 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 ?
123456789 var q = from P in context. products where p. productname. startswith ( "foo" ) select P; // before string commandtext = (objectquery ) 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.