PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 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:

<Function Name=Round ReturnType=Decimal>
<Parameter Name=val Type=Decimal />
<DefiningExpression>
CAST(val as Edm.Int32)
</DefiningExpression>
</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?

PrepAway - Latest Free Exam Questions & Answers

A.
public static class DecimalHelper
{
[EdmFunction(“SqlServer”, “Round”)]
public static Decimal Round(this Decimal Amt)
{
throw new NotSupportedException();
}
}

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/en-us/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.

2 Comments on “Which code segment should you use?

  1. Mike says:

    The NamespaceName parameter of the attribute is the namespace name of the conceptual model – which is not specified in the question. So B could also be correct.




    0



    0

Leave a Reply