You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to develop an application
that uses the Entity Framework. The application defines the following Entity Data Model.
Within the .edmx file, the following function is defined.
<Functlon Name-“Round” RetuEnType-“Decimal”>
<Parametec Name-“val” Type-“Decimal” />
<DefiningExpression> CAST(val As Edm.Int32)
</DefiningExpression>
</Function>
The application includes the following LINQ query.
Dim query = From detail In context.SalesOrderDetails Select detail.LineTotal.Round()
You need to ensure that the Round function executes on the database server when the query is
executed. Which code segment should you use?
A.
Module DecimalHelper
<EdmFunctlon(“SqlServer”, “Round”)>
<Extension()>
Public Function Round(ByVal Amt As Decimal) As Decimal
Throw New NotSupportedException() End Function
End Module
B.
Module DecimalHelper
<EdmFunction(“Edm”, “Round”)>
<Extension()>
Public Function Round(ByVal Amt As Decimal) As Decimal
Throw New NotSupportedException() End Function
End Module
C.
Module DecimalHelper
<Extension()> Public Function Round( ByVal input As Decimal) As SqlDecimal Return
SqlDecimal.Round(input/ 0) End Function
End Module
D.
Module PecimalHelper
<Extension()>
Public Function Round(ByVal Input As Decimal) As Decimal
Return Convert.ToDeclroal(Convert.ToInt32(Input)) End Function
End Module
Explanation:
EdmFunctionAttribute Class
(http://msdn.microsoft.com/enus/library/system.data.objects.dataclasses.edmfunctionattribute.aspx)
How to: Call Model-Defined Functions in Queries
(http://msdn.microsoft.com/en-us/library/dd456857.aspx)
The model-defined function has been created in the conceptual model, but you still need a way to
connect your code to it. To do so, add a function into your C# code, which will have to be annotated
with the EdmFunctionAttribute attribute. This function can be another instance method of the class
itself, but best practice is to create a separate class and define this method as static.