none
Extending LinqToEntities provider RRS feed

  • Question

  • I am trying to execute some logic on sql server (SQL COLLATE CLAUSE...) when there are string comparisons. I am also trying to keep the fluent api/poco/dbContext based architecture. So i tried following ...

    Wrapping the linqtoEntity provider : This did not lead me to anywhere since all examples i have seen tell you to modify the expression tree by writing a visitor/IQueryable etc.

    There doesnt seem to be a way to extend/wrap linqtoEntity provider to participate in sql generation. 

    This is a big deal for us, since we will end up writing our own orm ( which is very unfortunate)

    Am i out of luck here and is there no way of introducing new Linq Operators/Extension methods that can get translated to sql by EntityFramework ?

    Wednesday, August 29, 2012 7:19 PM

All replies

  • Hi Seeker,

    Welcome to the MSDN forum.

    Is what you need that you want to a provider which can generate SQL as you wish?

    After you execute a linq to entities query, the object service will translate query into a command tree. Then pass it to underlying entity client which is a data provider. If you want to generate custom SQL, you can write a data provider. When you write a provider for the Entity Framework, you must translate Entity Framework command trees into SQL that a specific database can understand, such as Transact-SQL for SQL Server or PL/SQL for Oracle. The ADO.NET Data Provider model provides a common managed interface in the .NET Framework for connecting to and interacting with a data store. Please refer to this page: http://msdn.microsoft.com/en-us/library/ee789835

    Here is an entity framework sample provider: http://archive.msdn.microsoft.com/EFSampleProvider

    In this sample you can find the SQL generation part which I think is helpful for you.

    In addition, you can take a look at this article: http://msdn.microsoft.com/en-us/magazine/cc301611.aspx

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by Alexander Sun Monday, September 10, 2012 7:23 AM
    Friday, August 31, 2012 7:29 AM
  • Sun thanks,

    all i want to do is to ADD COLLATE Clause to the order by statements and use fluent api to map my domain classes. 

    Do i have to write a new custom provider to do that ? There is no way to extend the current one ? Also is there a way to call user defined functions using code first ?

    Friday, August 31, 2012 2:08 PM
  • May be i am not communicating my question correctly

    I am trying to modify the SQL generated by Entity Framework ( i dont want to overtake it). I am trying to do this using code first approach ( no emdx).

    I dont want to write sql directly ( or else i will just use ado.net directly).  So if you can please answer following ...

    1. is there any way to modify ( not overtake) the generated output ? If not then

    2. is there any way to use user defined functions in EF ( code first only).

    Thanks

    Tuesday, September 4, 2012 5:45 PM
  • Hi Seeker,

    It is impossible to modify the generated output. Is the user defined functions you mentioned the Stored Procedures? If so, you can take a look at this page: http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=179481

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Alexander Sun Monday, September 10, 2012 7:23 AM
    • Unmarked as answer by seeker_123 Monday, September 10, 2012 5:23 PM
    Wednesday, September 5, 2012 7:25 AM
  • i cant use stored procs since what i need is extension methods to use in linq to entity queries.

    Overall pretty disappointing that MS decided to keep all their sql generation framework internal. Even expression classes in CommandTree namespace have internal constructors. 

    So i guess microsoft doesn't have a solution for folks who want to use EF code first and have a common database for all cultures ( even though sql server allows it, and we know they build everything for their own products)

    they should at least release source code for all versions of EF and stop disappointing their development community who has banked their careers on its technology.

    Monday, September 10, 2012 5:31 PM