I was wondering if it is possible to dynamically set the table mapping for the linq classes:
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.[Comfort 0601$Contact]")]
public partial class Contact : INotifyPropertyChanging, INotifyPropertyChanged
{
...
The reason I want to change this dynamically or programmatically is because the database I’m using is created by Navision. There the tables have a prefix of the company name to which these tables belong to. Therefor I would like to be able to change that prefix.
[global::System.Data.Linq.Mapping.TableAttribute(Name = "dbo.["+SPResources.Database.Company+"$Contact]")]
whit Company as:
public const string Company = "Comfort 0601";
I’ve tried this, but it only work if i declared Company as a constant.
The table structure between companies are identical. just the name & content change.
I hope someone can give some advice about this. I’m also not sure if it even is possible.
The answers of Brian and Gert are possible solutions for this problem. But changing the mapping at run-time is just not possible (as Brian mentioned).
As our project progressed we decided that if we would need another company name (which would mean that that build is for a different customer) we would just rebuild the project. That decision made the following solution possible:
We commented out the original mappings generated by Visual Studio:
Because we have our own partial class for every Linq class, we added the modified mapping at the top of our own class:
where our company will be:
If a rebuild is needed for a different company we simply change the Company variable.
Note: This only works properly if you don’t change your *.dbml file in VS. If you do, VS will automatically undo your changes.
Edit: As time has passed and I started to look more into the Entity Framework I found a more specific and suitable solution for this problem: http://www.codeproject.com/Articles/421643/How-to-Use-MVC-Net-on-the-Dynamics-NAV-Database-St