开发者

How to map EntitySql function to a differently named function in the store?

开发者 https://www.devze.com 2022-12-16 10:58 出处:网络
The question is: Given a database backend that understands LeftStr and RightStr: where, in a custom ADO.NET provider implementation, would I establish a mapping to the immutable EDM canonical function

The question is: Given a database backend that understands LeftStr and RightStr: where, in a custom ADO.NET provider implementation, would I establish a mapping to the immutable EDM canonical functions Left and Right?


So I am working with the SQLite ADO.NET provider and it works, more or less, until you bump up against some string functions that are present but named differently. Amongst the missing/mismapped functions are the canonical string functions Left and Right.

In the SQLite extension the equivalent functions are mapped to LeftStr and RightStr.

I have come up short when looking for information. Lacking documentati开发者_StackOverflowon for this scenario, or my lack of ability in finding it, I have step traced the call all the way into the factory method that creates the command with the generated SQL and suspect that the SemanticResolver is my best clue, but I have taken a few stabs in the dark by fudging with the only exposed seam I can find, ProviderManifest.xml, but am having no joy.


The answer assumes that SampleEntityFrameworkProvider is the reference implementation.

Each sql command to be executed against a provider implementation is processed by SampleEntityFrameworkProvider.SampleProviderServices.CreateDbCommandDefinition.

This method calls CreateCommand which in turn passes the DbCommandTree to SampleEntityFrameworkProvider.SqlGenerator, which is of type DbExpressionVisitor.

SqlGenerator's initializes static dictionaries of to handle translation.

I found what I was looking for in SqlGenerator.InitializeCanonicalFunctionHandlers and just followed the pattern as shown.

Simply add a new handler method to the dictionary keyed on the name of the EDM function you want to handle.

In this case the handler just needed to rename the function before it was written out.

Again there is a default implementation of this functionality, HandleFunctionDefaultGivenName(DbFunctionExpression e, string storeFunctionName).

0

精彩评论

暂无评论...
验证码 换一张
取 消