C# – Need to generate EDMX files and compile them

ccode generationcompilationdynamicedmx

My question might be little bit different or basic for advanced users here.

I have a web application which is customizable by administrators. This means, the admin can add new table schema or edit table columns, add new table columns etc. These changes are mapped to our logical objects (much similar to EDMX) which is published after the change. While publishing we generate Stored procedures with necessary changes that are required.

From UI we use these Logical objects to connect DB (using COM which understands the mapping and executes appropriate sprocs and views etc). Now i am thinking to use EF for replacing the Logical objects model which we are having currently. I can create the EDMX files (csdl,msl, ssdl, cs files) dynamically but i am not sure how to compile them and package the classes into DLL dynamically. This means, when i click the button the all edmx related files will be created and DLLs must be created based on CS files and the website must be able to access the new changes in the code.

Can you help me how to automatically and dynamically compile the cs files. I will not have the source code of other files (like default.aspx and others) at customer's end.

Thanks
Albert

Best Answer

Bepenfriends - rather than attempting a CSC from a shell, consider using a CSharpCodeProvider.CompileAssemblyFromFile.

One thing to be careful of: if you compile code and then try to compile it again, you may lock up on the assembly that was created. For this I created an AsyncCompiler which creates a new AppDomain, compiles in there, and then unloads the AppDomain.

It's some pretty hairy code but I'm doing this (generating the AEF XML files, generating code from them, and then compiling everything into an assembly) and it works well. The only thing I don't have quite right is dynamically importing stored procedures - my SSDL has them but not the CSDL or MSL. The search for a solution led me here.

I hope the keywords here are enough to set you off in the right direction.

Related Topic