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,
<Funccion Naroe=”Round” ReturnType=”Decimal”>
<Parameter Name=”val” Type=”Decimal” />
<DefiningExpression>
CAST(val as Edm.Int32)
</DefiningExpcession>
</Function>
The application includes the following LINQ query.
var 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.
public static class DecimalHelper
{
[EdmFunction(“SqlServer”, “Round”) ]
public static Decimal Round(this Decimal Amt)
{
throw new NotSupportedExceptionf);
}
}
B.
public static class DecimalHelper
{
[EdmFunction(“Edm”, “Round”) ]
public static Decimal Round(this Decimal Amt)
{
throw new NotSupportedException();
}}
C.
public static class DecimalHelper
{
public static SqlDecimal Round(this Decimal input) <
return SqlDecimal.Round(input, 0);
}}
D.
public static class DecimalHelper
{
public static Decimal Round(this Decimal input)
{
return (Decimal)(Int32)input;
}}
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.