Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Enitity Framework and COM
Message
De
14/09/2013 09:21:16
 
 
À
14/09/2013 09:15:24
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Versions des environnements
Environment:
C# 5.0
OS:
Windows 7
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web Service
Divers
Thread ID:
01583147
Message ID:
01583267
Vues:
39
>>>>Hi All,
>>>>
>>>>We are migrating an application from VFP to C#. One of the directives for the project is to maintain a common code base whenever possible. As we rewrite into C# we are producing DLLs to be used for data access and as a middle tier. We are looking to migrate portions of the legacy VFP app to using the C# DLLs as well go to only have to maintain a single code set. This can be accomplished by setting up the DLL classes as COM objects and this part works and the classes are available in VFP.
>>>>
>>>>The COM item I am looking to use in a basic data import. When the COM object reaches the point of connecting to the data via the enitity framework I recieve an error that the connection name cannot be found in the app.config file. The import runs just fine in C#, but fails via COM.
>>>>
>>>>Documentation that I have found indicates that DLLs cannot support a config file and that it instead relies on the web.config file of the consuming project. As I am calling the objects via COM there isn't a web.config in the parent project.
>>>>
>>>>Is anyone aware of a better way to do this?
>>>
>>>Add an app.config file to the dll project and specify the connection string there.
>>>
>>>Or programmatically pass the connection string as a parameter to the entity constructor...
>>
>>The project has an app.config, but at run-time it is ignored in favor of a web.config. In a COM object scenario there isn't a web.config. I will try passing the string through and see if the result is different. They removed where the DLL looks for dllname.DLL.CONFIG as a file and I was hoping for a replacement.
>
>You can use the app.config as per Rick's suggestion:
>
>E.g : If your DLL is MyDll.dll and your VFP exe is MyVFP.exe then copy the MyDll.dll.config file from the relevant .NET bin folder to the folder containing MyVFP.exe and rename it to MyVFP.exe.config. Won't work when debugging VFP but should work when running the EXE.....
>
>An alternative is to retrieve the config and create the DbContext in code:
            string configFile = @"D:\FullPath\MyDll.dll.config";
>
>            var map = new ExeConfigurationFileMap { ExeConfigFilename = configFile };
>            Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
>            ConnectionStringSettings css = configuration.ConnectionStrings.ConnectionStrings["MyEntities"];
>
>            MyEntities myEntities = new MyEntities(css.ConnectionString);
You'll need to provide the extra constructor in a partial class:
   public partial class MyEntities : DbContext
>    {
>        public MyEntities(string s)
>            : base(s)
>        {
>
>        }
>    }
Maybe add a method to the dll to accept the filename and pass that from VFP to make things more flexible ?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform