AnantLabs / codesmith

Automatically exported from code.google.com/p/codesmith
1 stars 0 forks source link

PLINQO L2S - Runtime Configurable Table Names #584

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Here is my use case:  I am developing a module for DotNetNuke using PLINQO.  
The problem is that DNN has config options to set a database table prefix (ex: 
"DNN_MyTable") and a database owner ("user1" instead of "dbo").

I need a way to dynamically change the table name and/or schema for my LINQ 
entities at runtime.  Because PLINQO doesn't support this, it's impossible to 
use PLINQO to build commercial modules for DNN.  This feature would also solve 
problems for other commercial applications, and scenarios where the schema name 
is different in each environment (dev, staging, production).

I found a potential solution, but it would need to be part of the PLINQO code 
generation.  
http://weblogs.asp.net/guybarrette/archive/2008/07/23/linq-to-sql-dynamic-mappin
g.aspx

Thanks for your consideration!

Original issue reported on code.google.com by KevinLa...@gmail.com on 13 May 2011 at 6:01

GoogleCodeExporter commented 9 years ago
Hello,

We provide a public static field on the generated DataContext called 
MappingCache. If you created a map file using a custom template 
(http://community.codesmithtools.com/CodeSmith_Community/b/blake/archive/2011/01
/19/extending-the-codesmith-generator-plinqo-templates.aspx) or SQLMetal, you 
could set the MappingCache field on application startup (Global Application 
Object or during application Init) using the steps from the blog. From this 
point any call using the generated DataContext would use the mapping file.

Does this solution work for you? Also the generated DataContext has a 
OnCreated() partial method that you could possibly hook into, but I think it 
would be better to do this during application launch.

Thanks
-Blake Niemyjski

Original comment by bniemyjski on 18 May 2011 at 7:01

GoogleCodeExporter commented 9 years ago
Blake,

Thanks for your reply.  I think the biggest roadblock is that I can't predict 
the table prefix or database owner.  It can vary with every DNN installation.  
It's not feasible to generate a new mapping file for each customer's 
environment.  I think the only solution is to be able to set the table name at 
runtime (which isn't natively supported by LINQ-to-SQL).

I found a "Model Adapter" for L2S that may solve the issue, but the project is 
not being actively developed:  http://dnnlinqtosqladapter.codeplex.com/  I also 
saw a model adapter for Entity Framework that has some nice features:  
http://efmodeladapter.codeplex.com/

I'm hoping one (or both) of these will be of interest to CodeSmith as potential 
enhancements to PLINQO.  It would solve problems in a number of environments 
and use cases.

Thanks again for your consideration!

-Kevin

Original comment by KevinLa...@gmail.com on 18 May 2011 at 8:33

GoogleCodeExporter commented 9 years ago
Hello,

Thanks for your feedback. It looks like both of those projects haven't been 
updated in quite a while. I'll bring this up to the team during our next scrum 
meeting and see what the team thinks.

Thanks
-Blake Niemyjski

Original comment by bniemyjski on 19 May 2011 at 4:03

GoogleCodeExporter commented 9 years ago
Hello,

We talked this over as a team and are considering adding this to a future 
version of PLINQO (Depending on number of requests). This behavior can already 
be safely added to the generated solution following the tutorials above while 
retaining active generation support.

Please let us know if you have any questions or concerns

Thanks
-Blake Niemyjski

Original comment by bniemyjski on 20 May 2011 at 4:54