What should you do?

You use Microsoft Visual studio 2010 and Microsoft NET Framework 4.0 to create an application.
The application uses the ADO.NET Entity Framework to model entities. The model includes the entity shown in the following exhibit:

You need to add a function that returns the number of years since a person was hired.
You also need to ensure that the function can be used within LINQ to Entities queries. What should you do?

You use Microsoft Visual studio 2010 and Microsoft NET Framework 4.0 to create an application.
The application uses the ADO.NET Entity Framework to model entities. The model includes the entity shown in the following exhibit:

You need to add a function that returns the number of years since a person was hired.
You also need to ensure that the function can be used within LINQ to Entities queries. What should you do?

A.
//Add the following conceptual model function returns the number of years since an instructor was hired
<Function Name=”YearsSince” ReturnType=”Edm.Int32″>
<Parameter Name=”date” Type=”Edm.DateTime” />
<DefiningExpression>
Year(CurrentDateTime()) – Year(date)
</DefiningExpression>
</Function>
// add the following method to your application and use an EdmFunctionAttribute to map it to the conceptual model function:
[EdmFunction(“SchoolModel”, “YearsSince”)]
public static int YearsSince(DateTime date){
throw new NotSupportedException(“Direct calls are not supported.”);
}

B.
//Add the following conceptual model function returns the number of years since an instructor was hired
<Function Name=”YearsSince” ReturnType=”Edm.Int32″>
<Parameter Name=”date” Type=”Edm.DateTime” />
<DefiningExpression>
Year(CurrentDateTime()) – Year(date)
</DefiningExpression>
</Function>
// add the following method to your application and use an EdmFunctionAttribute to map it to the conceptual model function:
[EdmFunction(“SchoolModel”, “YearsSince”)]
public static int YearsSince(DateTime date){
return CurrentDateTime() – Year(date);
}

C.
//Add the following conceptual model function returns the number of years since an instructor was hired
<Function Name=”YearsSince” ReturnType=”Edm.Int32″>
<Parameter Name=”date” Type=”Edm.DateTime” />
<DefiningExpression>
YearsSince(DateTime date)
</DefiningExpression>
</Function>
// add the following method to your application and use an EdmFunctionAttribute to map it to the conceptual model function:
[EdmFunction(“SchoolModel”, “YearsSince”)]
public static int YearsSince(DateTime date){
return CurrentDateTime() – Year(date);
}

D.
Use the Entity Data Model Designer to create a complex property named
YearsSinceNow that can be accessed throuqh the LINQ to Entites query at a Later time

Explanation:
How to: Call Model-Defined Functions in Queries
(http://msdn.microsoft.com/en-us/library/dd456857.aspx)

How to: Call Model-Defined Functions as Object Methods
(http://msdn.microsoft.com/en-us/library/dd456845.aspx)



Leave a Reply 1

Your email address will not be published. Required fields are marked *


Filip

Filip

B looks correct, except there is not CurrentDateTime() function defined in code.