我最近开始使用《EF诉4法》只为我正在从事的一些项目的图书馆。 然而,我已经走进了一条na子。 我看不出连接铺设的适当格式。 我使用了以下法典来建立连接线:
string connectionString = new EntityConnectionStringBuilder
{
Provider = "System.Data.SqlClient",
ProviderConnectionString = new SqlConnectionStringBuilder
{
DataSource = "localhost",
InitialCatalog = "ASM_Testing",
IntegratedSecurity = true,
Pooling = false
}.ConnectionString
}.ConnectionString;
然而,使用这一术语会造成以下错误:
Specifications_for_EntityContext.When_logging_in_application_with_valid_app_role_and_password.Login_should_be_successful : System.ArgumentException : Some required information is missing from the connection string. The metadata keyword is always required.
Stack Trace:
at System.Data.EntityClient.EntityConnection.ValidateValueForTheKeyword(DbConnectionOptions effectiveConnectionOptions, String keywordName)
at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
at System.Data.Objects.ObjectContext..ctor(String connectionString)
at ASM.Data.EntityContext..ctor(String connectionString) in C:UsersJon RistaTFSAdvanced Service ManagementTrunkMainSourceASM.DataEntityContext.cs:line 16
at Specifications_for_EntityContext.Behaves_like_EntityContext_connected_to_a_database.TestableEntityContext..ctor(String connectionString) in C:UsersJon RistaTFSAdvanced Service ManagementTrunkMainSourceTests.ASM.DataEntityContextFacts.cs:line 165
at Specifications_for_EntityContext.Behaves_like_EntityContext_connected_to_a_database.InitializeContext() in C:UsersJon RistaTFSAdvanced Service ManagementTrunkMainSourceTests.ASM.DataEntityContextFacts.cs`e`enter code here`nter code here`:line 160
at ASM.Testing.xUnit.ObservationCommand.Execute(Object testClass) in C:UsersJon RistaTFSAdvanced Service ManagementTrunkMainSourceASM.Testing.xUnitObservationCommand.cs:line 24
at Xunit.Sdk.FixtureCommand.Execute(Object testClass)
at Xunit.Sdk.BeforeAfterCommand.Execute(Object testClass)
at Xunit.Sdk.LifetimeCommand.Execute(Object testClass)
at Xunit.Sdk.TimedCommand.Execute(Object testClass)
at Xunit.Sdk.ExceptionAndOutputCaptureCommand.Execute(Object testClass)
我看不到任何元数据......因为我只使用《法典》,我是一把一把。 任何见解都受到高度赞赏。
建造商班产生的连接线如下:
provider=System.Data.SqlClient;provider connection string="Data Source=localhost;Initial Catalog=ASM_Testing;Integrated Security=True;Pooling=False"
<<>Working Example (根据已接受的答复):
有必要利用“背景”来创造任何一种使用一种只使用代码的方式的背景。 对于寻求解决同一问题的人来说,这是一个行之有效的例子:
protected override void InitializeContext()
{
string connectionString = new SqlConnectionStringBuilder
{
DataSource = "localhost",
InitialCatalog = "Testing",
IntegratedSecurity = true,
Pooling = false
}.ConnectionString;
var connection = new SqlConnection(connectionString);
var builder = new ContextBuilder<TestableEntityContext>();
m_context = builder.Create(connection);
}