0

I'm using Entity Framework 4.1 Code First, Sqlite and WPF.

I want to redefine the app.config ConnectionString to sqlite, so I can define the Data Source (path for Sqlite database file) at runtime.

My guess is using the EntityConnectionStringBuilder to create the connection string. But I don't know what the event where I build and assign the connection string so the EF Code First will detect the change and will use the newer ConnectionString in all the code for the application (instead to use the app.config ConnectionString). I imagine that it's to be placed on Application_Startup event, but I don't know if this is the best pratice.

Thank you in advance.

4

2 回答 2

2

如果这就是你所追求的,

您可以在运行时通过DbContext(string)构造函数传递字符串 - 请参阅此处了解更多DbContext(string)

您还可以让您的上下文实现采用该参数并将其传递给baseDbContext。

希望这可以帮助

于 2012-04-13T17:51:20.730 回答
0

如果您使用的是 EF 4.1 CF,那么一旦您生成 *.edmx 文件,它应该会自动创建您的 app.config。如果您有现有的,则无需创建自己的 app.config 或更改它。

于 2012-04-13T13:27:10.470 回答