Moving Entity Framework model into class library from web project

前端 未结 2 796
梦谈多话
梦谈多话 2020-12-09 04:19

I am using Entity Framework and recently came to realize the benefits of having your EF model in another project within the same solution so that I can build multiple UIs fr

2条回答
  •  再見小時候
    2020-12-09 04:47

    This is by design; while the config file in the class library is what the designer will use, the configuration file of the actual application is what will get used at runtime. Whether that's Web.config for an ASP.NET project or App.config for a Winforms or WPF project, it's the application configuration file (or something higher up, like Machine.config) that will be used; the file in the class library is not part of the application.

    If you're trying to provide an EF model that will work without having to specify the connection string in the application or web configuration file, then you'll have to store the connection string some other way (you could always hard-code it) and pass it into the appropriate overload of your context's constructor.

    My solution is generally to provide a static parameterless function on the context itself that calls this overload with the appropriate connection string.

提交回复
热议问题