Entity Framework: Stored Procedures && EDM

Source: Internet
Author: User
Tags builtin

The use of stored procedures (SPS) in the EDM seems to me to be more concerned with the performance of the SP in the edmx file than the SP's functionimport in the EDM.

After I add the stored procedure SP GetOrder to the EDM and finish FunctionImport, I can open the edmx file to view the implementation of GetOrder in SSDL (), Csdl,c-s mapping:

SDL: <function name= "GetOrder" aggregate= "false" builtin= "false" niladicfunction= "false" iscomposable= "false" parametertypesemantics= "allowimplicitconversion" schema= "dbo" >
<parameter name= "OrderID" type= "int" Mode = "in"/>
</Function>

About parameters in function: For iscomposable,builtin These 2 parameters are very important to specify that the return result will be returned by the query of the stored procedure, without generating additional SQL (for LINQ, no need to be interpreted in time) because it is set to false. There's nothing else to say.

CSDL: <functionimport name= "getorders" entityset= "Orders" returntype= "Collection (northwindefmodel.orders)" >
<parameter name= "OrderID" mode= "in" type= "Int32"/>
</FunctionImport>

ReturnType is a collection, I tried to modify it to a single entity (let it return a non-collection type), but it is not supported in the EF v1.

If the SP is just that in the edmx file, there's really nothing to write about. But not only that, because there are commandtext,out put arguments in addition to return type.

. CommandText

There is a CommandText tag underneath the XML node of the function, which allows us to customize SQL in the function of the SSDL layer, rather than just the SP, where it is better to embed SQL in the SSDL layer in some specific scenarios than SP, After all, the SP exists on the database, which makes it necessary to manage the data not only for the application but also for the CommandText attribute in the function 2 to achieve some sort of balance. Here are examples of using CommandText

 ssdl:<function name= "Customerwithhighestsales" aggregate= "false" builtin= "false" niladicfunction= "false" Iscomposable= "false" parametertypesemantics= "allowimplicitconversion" schema= "dbo" > <!--cannot use command tex T with functions. Allows to execute multiple statement.--> <CommandText> select * from Customers where custo Merid = (select top 1 o.customerid from the Orders o join OrderDetails od on o.orderid = od. OrderID GROUP BY O.customerid Order by SUM (OD. UnitPrice * od. Quantity) desc </CommandText> </Function> CommandText content in SSDL is to find Highestsales's customer Csdl: <f Unctionimport name= "Customerwithhighestsales" entityset= "Customers" returntype= "Collection" ( northwindefmodel.customers) "> </FunctionImport> msdl: <functionimportmapping functionimportname=" Customerwithhighestsales "Functionname=" NorthwindEFModel.Store.CustomerWithHighestSales/> 

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.