類的DbContext類的言論有充分的解釋。
總之:
- 你的第一個例子可能會導致所謂的「mainConnectionString」創建數據庫。
- 名= XXXX的名字
某些工具做投入的App.config條目你看起來的app.config進行的ConnectionStrings。
您鏈接的在線文檔明確指出幫助的位置。
在線求助說:
使用給定的字符串作爲名稱 或連接字符串數據庫的連接將被 給哪個構造一個新的上下文實例。請參閱課程註釋以瞭解如何使用它來創建 連接。
如果你去到類的言論,你會發現一個完整的解釋....
/// The connection to the database (including the name of the database) can be specified in several ways.
/// If the parameterless DbContext constructor is called from a derived context, then the name of the derived context
/// is used to find a connection string in the app.config or web.config file. If no connection string is found, then
/// the name is passed to the DefaultConnectionFactory registered on the <see cref="T:System.Data.Entity.Database"/> class. The connection
/// factory then uses the context name as the database name in a default connection string. (This default connection
/// string points to .\SQLEXPRESS on the local machine unless a different DefaultConnectionFactory is registered.)
/// Instead of using the derived context name, the connection/database name can also be specified explicitly by
/// passing the name to one of the DbContext constructors that takes a string. The name can also be passed in
/// the form "name=myname", in which case the name must be found in the config file or an exception will be thrown.
/// Note that the connection found in the app.config or web.config file can be a normal database connection
/// string (not a special Entity Framework connection string) in which case the DbContext will use Code First.
/// However, if the connection found in the config file is a special Entity Framework connection string, then the
/// DbContext will use Database/Model First and the model specified in the connection string will be used.
/// An existing or explicitly created DbConnection can also be used instead of the database/connection name.
/// A <see cref="T:System.Data.Entity.DbModelBuilderVersionAttribute"/> can be applied to a class derived from DbContext to set the
/// version of conventions used by the context when it creates a model. If no attribute is applied then the
/// latest version of conventions will be used.
謝謝您的回答,它能指出我錯過了那篇文章的確切說法。 – Jonathon
「看到課堂講話」,「如果你去課堂講話...」 - - 定位這是不明顯的。你是怎麼找到它們的? – redwards510
@ redwards510我使用Resharper dotpeek來反編譯源代碼。它可以免費安裝。這是一個免費軟件。但還有其他工具,如.net反射器 –