Entity Framework Sqlfunctions teaches you how to call the SQL Server method's function stub in EF

Source: Internet
Author: User

Today is a study of the day of the Sqlfunctions, consulted a few groups of cattle, incredibly found that everyone is more unfamiliar with this,

Some even pointed to the method in EF that cannot be called in SQL Server.

Because I've had a Sqlmethod in LINQ to SQL before, I think EF must be able to do it.

First of all, a short introduction to EF6 and EF5, when you nuget a EF5 package, only entityframework, and EF6 do EntityFramework and Entityframework.sqlserver,

There are a lot of differences between the 2 of them.

In the EF5 environment, how do we use sqlfunctions?

First add the EF environment, add Syste.Data.Entity to the reference, and then add the namespace

using System.Data.Objects.SqlClient;

Then write a controller test

1  Publicactionresult Index ()2         {3             intCount =0;4             using(Models.testprojectdbentities db =Newmodels.testprojectdbentities ())5             {6                 varQuery = fromCinchDb. AdmininfoeswhereSqlfunctions.square (1.00) ==c.ordersSelectC;7Count =query.tolist (). Count ();8             }9Viewbag.count =Count;Ten             returnView (); One}

is operating normally.

EF6 Environment,

There are entityframework and entityframework.sqlserver in our references,

Then we add the namespace

using System.Data.Entity.SqlServer;

Notice, and EF5 under the namespace is not the same, this place I also have a misunderstanding, when my add is using System.Data.Objects.SqlClient;

This error is really strange, I find a lot of reasons on the internet has not been found, the last chance to get this result.

Then we run the above test code, it should also run through.

Sqlfunctions provides a lot of methods, this is relatively simple, do not do a detailed introduction.

This group provides ASP. NET Mvc,ef,linq,web API technical support, do not care about people, care about human spermatogonial.
ASP. NET MVC Group 171560784
Invite all the experts, beginners to join.

Related Article

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.