EF Execute SQL query

Source: Internet
Author: User

1、无参数查询 var model = db.Database.SqlQuery<UserInfo>( "select* from UserInfoes " ).ToList(); 2、有参查询 var model = db.Database.SqlQuery<UserInfo>( "select* from UserInfoes where [email protected] " , new SqlParameter( "@ID" ,id)).ToList(); 3、结合linq查询 var model = ( from p in db.userinfo.SqlQuery( "select * from UserInfoes where [email protected]" , new SqlParameter( "@ID" , 1)) select p).ToList(); 4:EF原始查询单独表 model = db.userinfo.OrderByDescending(a => a.ID).Skip(10 * (当前页 - 1)).Take(10).ToList(); 5,EF 执行存储过程或delete 删除语句 SqlParameter[] para = new SqlParameter[] { new SqlParameter( "@ID" ,id) }; db.Database.ExecuteSqlCommand( "delete UserInfoes  where [email protected]" , para); 存储过程 删除,有几个参数,存储后面要带几个参数以逗号分隔 SqlParameter[] para = new SqlParameter[] { new SqlParameter( "@ID" ,id) }; db.Database.ExecuteSqlCommand( "sp_Userinfos_deleteByID @ID" , para);

EF Execute SQL query

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.