nerdexam
Microsoft

70-516 · Question #42

How do you call a model-defined function as static method on a custom class?

The correct answer is A. Add a class to your application with a static method that does the following. To call a model-defined function as static method on a custom class: 1.Add a class to your application with a static method that does the following: - Maps to the function defined in the conceptual model. To map the method, you must apply an EdmFunctionAttribute to the method…

Querying Data

Question

How do you call a model-defined function as static method on a custom class?

Options

  • AAdd a class to your application with a static method that does the following:
  • BAdd a class to your application with a static method that does the following:
  • CAdd a class to your application with a static method that does the following:
  • DAdd a class to your application with a static method that does the following:

How the community answered

(48 responses)
  • A
    79% (38)
  • B
    2% (1)
  • C
    13% (6)
  • D
    6% (3)

Explanation

To call a model-defined function as static method on a custom class: 1.Add a class to your application with a static method that does the following: - Maps to the function defined in the conceptual model. To map the method, you must apply an EdmFunctionAttribute to the method. Note that the NamespaceName and FunctionName parameters of the attribute are the namespace name of the conceptual model and the function name in the conceptual model, - Accepts an IQueryable argument. - Returns the results of the Execute method that is returned by the Provider property. 2.Call the method as a member a static method on the custom class - function mapping <Function Name="GetDetailsById" ReturnType="Collection(AdventureWorksModel.SalesOrderDetail)"> <Parameter Name="productID" Type="Edm.Int32" /> <DefiningExpression> FROM AdventureWorksEntities.SalesOrderDetails AS s WHERE s.ProductID = productID </DefiningExpression> public partial class AdventureWorksEntities : ObjectContext { [EdmFunction("AdventureWorksModel", "GetDetailsById")] public IQueryable<SalesOrderDetail> GetDetailsById(int productId) return this.QueryProvider.CreateQuery<SalesOrderDetail>(Expression.Call( Expression.Constant(this), (MethodInfo)MethodInfo.GetCurrentMethod(), Expression.Constant(productId, typeof(int)))); How to: Call Model-Defined Functions as Object Methods How to: Call Model-Defined Functions in Queries

Topics

#model-defined function#EdmFunction attribute#LINQ to Entities#custom class

Community Discussion

No community discussion yet for this question.

Full 70-516 Practice