what are 'EdmFunctions' for?

2019-03-05 11:42发布

问题:

i saw the System.Data.Common.CommandTrees.ExpressionBuilder.EdmFunctions static class accidently, that contains a set of extension methods on System.Data.Common.CommandTrees.DbExpression, like AddDays, Concat,.... which bring back System.Data.Common.CommandTrees.DbFunctionExpression as return type, this static methods if needs to an argument, they only accept a System.Data.Common.CommandTrees.DbExpression type, in addition i look over the System.Data.Common.CommandTrees.DbExpression and i saw this class is abstract and by its static members you can create a System.Data.Common.CommandTrees.DbExpression, and send them to System.Data.Common.CommandTrees.ExpressionBuilder.EdmFunctions to use its extension methods,

my questions are:

  • what are these extensions for ?
  • how and where can we use this extension methods ?
  • have these extension methods mapped to canonical functions and are as helper method for using in Linq, like System.Data.Objects.EntityFunctions's methods or System.Data.Objects.SqlClient.SqlFunctions's Methods ?

whereas there is a attribute with name System.Data.Metadata.Edm.EdmFunction and by this, you can create CLR functions and map them to created model-defined functions for using in Linq,

  • is there a relation between these ?

could you attach any sample? or link to any documentaion?

回答1:

These methods are not meant for general consumption, you continue to use SqlFunctions or EntityFunctions in client code. They are the stock implementations of the canonical functions that can execute on an arbitrary provider. Microsoft includes the providers for XML, BCL collections and Entity SQL. Somebody else can create a provider to, say, their own dbase engine or ORM.

The mapping from, say, EntityFunctions.AddDays() to EdmFunctions.AddDays() occurs dynamically when the query comprehension is executed.