Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Entity Framework Perplexities
Message
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Versions des environnements
Environment:
C# 5.0
OS:
Windows 10
Network:
Windows Server 2012
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01646424
Message ID:
01646512
Vues:
25
>There are a couple of add-ins which will handle transforms (but I haven't tried them) : SlowCheetah and SlowMonkey (both on nuGet)
>
>But I think you can subclass the DbConnectionClass, set the parameters accordingly and pass this to the DbContext constructor ?

Yes, that's the plan.

In fact I wanted to overload the constructor with a parameter in a partial class taht would not live in the generated project.

In the Generated DBContext Project
    public partial class PluczExp_PluczContext : DbContext
    {
        public PluczExp_PluczContext()
            : base("name=PluczExp_PluczConnection")
and in the production project I wanted to have
    public partial class PluczExp_PluczContext : DbContext
    {
        public PluczExp_PluczContext(string connectionName)
            : base(connectionName)
so that I don't have to change the generated DbContext class.

Have tried that before and did not work.

You're suggesting to derive from PluczExp_PluczContext , but then I'm not sure how I call the base (red in the cheeks).
Thanks for shedding some light on this.





>
>>Thanks Viv. But I have reasons to believe that this Transform logic does not apply to app.Config (Desktop Applications).
>>There is no Transform Preview on the rightclick menu even after I implement the tranform markups.
>>
>>I'm now looking for ways where I can change the connection parameters in real time, before I connect (I.e. before I instatiate the DBContext). My workstation is a portable pc , and based on the wireless I determine "where I am", and based on that I want to inject the connection parameters at runtime (production sql server in the office ; or sql server on my local machine anywhere else).
>>
>>Wish me luck.
>>
>>>>>
>>>>>I usually create a custom configuration (although you might be able to use the standard 'Debug' and 'Release' configurations) and use web.config transforms. Little bit of work setting up but well worth it once in place since you only have to change 'common' settings in one place. See:
>>>>>https://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx
>>>>
>>>>Many thanks. As always.
>>>>
>>>>I guess the same logic would apply to app.config.
>>>>
>>>>It's not exactly what I was looking for, but it does give me some clue of how to proceed.
>>>
>>>It's pretty straightforward. If you can use, say, the standard release config to change the default then it should just look like this:
<?xml version="1.0"?>
>>>
>>><configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
>>>   <connectionStrings>
>>>      <add name="PGSheetControlEntities" connectionString="metadata=res://*/PGSheetModel.csdl|res://*/PGSheetModel.ssdl|res://*/PGSheetModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=192.168.0.15;Initial Catalog=PGSheetControl;User ID=sa;Password=xxxxx ;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"
>>>        xdt:Transform="Replace" xdt:Locator="Match(name)"/>
>>>  </connectionStrings>
>>></configuration>
i.e. copy the default entry for the 'add' attribute, change the Data Source (and any other parameters that are different and add the xdt:Transform attribute. You can right click on the release config and use 'Preview Transform' to confirm that everything is correct.

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform