-
Notifications
You must be signed in to change notification settings - Fork 874
EF support improvement #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Here is the long long detailed procedures to test my fix. Prepare a PostgreSQL instance for ready to use.Assuming,
Create a function.Example: Build your NpgsqlOpen Npgsql2012.sln with VS2012 Express for Desktop. Select configuration Release-net45 Build Npgsql Register your Npgsql and dependent assembly into GACCheck your installed assembly signature. Edit machine.configC:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config Add new element to DbProviderFactories. New C# projectLaunch VS2012 Express for Desktop. New Project ConsoleApplication7 Invoke EdmGenLaunch Command Prompt. Move your current directory to ConsoleApplication7. Invoke EdmGen then. Output sample: Edit ssdlOpen ConsoleApplication7.ssdl Edit Function passthru. Replace "ConsoleApplication7.Store" with "public". Save it. Edit mslOpen ConsoleApplication7.msl Add FunctionImportMapping. Save it. Edit csdlOpen ConsoleApplication7.csdl Add FunctionImport Make sure you add FunctionImport into EntityContainer, not EntityType. Save it. Generate new object layer by EdmGenInvoke EdmGen. Add assembly referencesAdd reference to System.Data.Entity Add object layerAdd the file to your C# project ConsoleApplication7.ObjectLayer.cs Add schema filesAdd your schema files into your project. ConsoleApplication7.csdl Copy your schema files into bin dir.About 3 files, set "Copy to Output Directory" property to "Copy if newer". Edit App.configAdd your connectionString into App.config Edit Program.csMake sure to call function passthru. Run your applicationThe following result is brought if everything goes well. You may get ArgumentException within EntityCommandCompilationException, if your Npgsql doesn't have DbFunctionCommandTree support. Otherwise you might get other exception messages. |
|
That's awesome, Kenji! If you don't mind, I'll later create add your instructions to our User Manual so others can benefit from your instructions. Thank you very much! |
|
Hi. I don't mind the usage of procedures. I'll help you, for example, if you need more detailed explanation. thanks |
|
I just tested it and it worked like a charm! I used VS2013 though because I had a problem with VS2012 after I installed VS2013. But I think the update 4 for VS2012 will fix this problem and I'll test it in VS2012 too. One question: why is needed to make those changes to generated files? Is Npgsql support missing to get those files correctly built? Or are those changes also needed when working with SQL Server? (I don't have much experience with Entity Framework with SQL Server) Other than that, I think those changes are very good. Excellent work, Kenji Uno! Thank you very much!
I'll add your documentation to our user manual. Thank you too for your contributions! |
|
Hi.
It'll be implementation issue of EdmGen (and also VS Designer support). We can get same result with SQL Server provider. I've confirmed it a hour ago. Perhaps my problem may be insignificant one. Many people won't feel so much difficulty, because they don't need to use StoredProcedures/Functions through EF support. We can easily call StoredProcedures/Functions by invoking NpgsqlCommand. I'm lazy man. So I wrote EdmGen06. It can generate schema files with StoredProcedures/Functions generation support. The fix of NpgsqlSchema.ssdl and NpgsqlSchema.msl was needed to complete EdmGen06. thanks |
|
Excellent! When possible, please, add an example using your tool so we can add it to our user manual. |
|
Another comment: You have a class called Eut in SqlFunctionGenerator which has a single method called escape which just returns the parameter. Is this intended? Would it be possible to just use the parameter directly? Would it be possible for you to squash or remove the first commit? It is empty! (I don't know how you could get git to do that in first place :) ) Thanks in advance. |
|
Hi.
Thanks. It forgot I have placed EUt. I have tested if we can call upper-case-first function like public.PassThrough without quote marks. It couldn't. So I will add some codes for quote marks like "public"."PassThrough".
Ok :)
Ok! |
Fixed EndProperty names in msl's ViewConstraintColumns. Appended missing Association/AssociationSet in ssdl. Added experimental SqlFunctionGenerator for EF Function call support.
|
Hi. I have pushed a new commit, that is produced by TortoiseGit's Combine to one commit, with force push option. About EUt, I have replaced with SqlBaseGenerator.QuoteIdentifier that is already used in other EF support codes. I'll write example with: ef_code_first_sample as ef_db_first_sample :) http://fxjr.blogspot.jp/2013/06/npgsql-code-first-entity-framework-431.html |
Great!
Excellent! I'll check it.
:) I'm looking forward it. |
ef_db_first_sample instructionTested on:
Create a databaseWith command line: If you can invoke SQL commands, try: Add role "npgsql_tests" with pass "npgsql_tests"Invoke SQL commands: Create sample tables: Blog and PostInvoke SQL commands: Grant permissions to role npgsql_tests: Generate an edmx file from your databaseEdmGen06 is a partially compatible tool to Microsoft's EdmGen. The latest binary releases will be available at https://github.com/kenjiuno/EdmGen06/wiki Extract the files somewhere. Launch command prompt. Enter EFv4 directory. Try next command. You will see output like following lines: Blogging.App.configOpen "Blogging.App.config" generated by EdmGen06. Take the element and its children: <system.data> Create an application with VisualStudio2012ExpressForDesktopTemplate: Console Application (C#) Edit your App.config
Your App.config will look like: Add Blogging.edmxAdd "Blogging.edmx" generated by EdmGen06, to your project. Edit the property of Blogging.edmxCustom tool: EntityModelCodeGenerator Copy Npgsql.dll and Npgsql.EntityFrameworkLegacy.dllCopy "Npgsql.dll" and "Npgsql.EntityFrameworkLegacy.dll" files into your project folder. Edit the property:
Reading & Writing DataEdit your Program.cs Launch, and enjoy it! |
|
Awesome, Kenji! I'll create some wiki pages with your documentation. Thank you very much! |
|
Just started to create the Npgsql user manual wiki page and I added your ef_db_first sample: https://github.com/npgsql/Npgsql/wiki/User-Manual#ef_db_first_sample-instruction Thank you for creating this explanation, Kenji! It will help many Npgsql users. |
|
Small suggestion: since there's lots of stuff in the manual and EF doesn't necessarily interest everyone, maybe a separate wiki page on EF? |
I thought about that but in the opposite direction. :) But I think we can try another approach: Create another wiki page specifically to EF ( and later create one for DDEX and any other macro topic) and add a link to them in the User Manual. What do you all think? |
|
Sounds great to me! We can split off any subject into its own page and have links to make things clearer... Note that the wiki has a "Root" page, which is what you see when you click on "Wiki" in github. I've already placed links there to some stuff, feel free to organize as you see fit... |
|
Great! Yes, I saw you placed some links there. I'll make the changes... |
|
Thank for you update the wiki! |
You are welcome! |
|
Superceded by #129 |
SqlFunctionGenerator appended:
Changes for NpgsqlSchema.ssdl
Changes for NpgsqlSchema.msl