You must create and compile EDMX files

My question may be a little different or basic for advanced users here.

I have a web application that is configured by administrators. This means that the administrator can add a new table schema or edit table columns, add new table columns, etc. These changes are mapped to our logical objects (which is very similar to EDMX), which is published after the change. When publishing, we create stored procedures with the necessary changes.

From the UI, we use these Logical Objects to connect the database (using COM, which understands the mapping and performs the corresponding sprocs and views, etc.). Now I am thinking of using EF to replace the logical entity model that we currently have. I can create EDMX files (csdl, msl, ssdl, cs) dynamically, but I'm not sure how to compile them and dynamically split classes into DLLs. This means that at the click of a button, all edmx-related files will be created, and the DLLs must be created based on the CS files, and the website should have access to new code changes.

Can you help me how to automatically and dynamically compile cs files. I will not have the source code of other files (e.g. default.aspx, etc.) on the client side.

Thanks Albert

+4
source share
2 answers

Bepenfriends - Instead of trying CSC from the shell, consider using CSharpCodeProvider.CompileAssemblyFromFile.

Be careful: if you compile the code and then try to compile it again, you can block the assembly that was created. To do this, I created AsyncCompiler, which creates a new AppDomain, compiles there, and then unloads the AppDomain.

This is some pretty hairy code, but I do it (by generating AEF XML files, by generating code from them, and then compiling everything into an assembly), and it works well. The only thing I don't have is to dynamically import stored procedures - I have SSDL, but not CSDL or MSL. Finding a solution brought me here.

I hope that the keywords here are enough for you to disable them in the right direction.

+2
source

I actually have no final answer for you - but two possible solutions that you could study, perhaps in the near future:

1) There is a set of CodeSmith templates called PLINQO that generate your Linq-to-SQL (DBMX) model and related * .cs files from your database. I asked them about Entity Framework support, and they confirmed that they are working on it - so maybe they will do it soon.

Since these are code generation and model generation templates, you can definitely take them for Linq-to-SQL and configure them for EDMX. A bit of work, but definitely possible. Once you have the * .cs and * .edmx files, you can generate the resulting assembly from it using the CSC command-line compiler (C #), which is installed on every computer that has .NET installed.

2) With .NET 4, the new Entity Framework 4 will include T4 templates (another code generation technology) that will allow you to customize code generation. The same situation applies here: you can externally generate your EDMX model and its associated * .cs files for classes and generate the assembly on the fly from these templates.

See another blog post on this topic, and you should find a lot of information at startup (or bing) or "EF4 T4 templates".

Hope this helps at least a bit!

0
source

Source: https://habr.com/ru/post/1299891/


All Articles