我使用这条指令创建了一个 ADO.NET 实体数据模型。我有两个新课程:
namespace Parser
{
public partial class advert : EntityObject
{
///////////
}
public partial class test_workEntities1 : ObjectContext
{
///////
}
}
然后我创建了以下类:
namespace Parser
{
public class BdProvider
{
public void InsertAdv()
{
advert adv = new advert();
test_workEntities1 f = new test_workEntities1();
adv.adress = "adress 1";
adv.const_link = "domain.com";
adv.count_room = 10;
f.advert.AddObject(adv);
}
}
}
我创建了以下控制台应用程序:
namespace TestApp
{
class Program
{
static void Main(string[] args)
{
BdProvider bd = new BdProvider();
bd.InsertAdv();
Console.ReadKey();
}
}
}
当我运行应用程序时,我看到:
指定的命名连接在配置中未找到,不打算与 EntityClient 提供程序一起使用,或者无效
堆栈跟踪:
System.ArgumentExceptionнеобработано消息=Указанноеименованноесоединениененайденовконфигурации,непредназначалосьдляиспользованияспоставщикомEntityClientилинедопустимо。Source=System.Data.Entity StackTrace: • System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString) • System.Data.EntityClient.EntityConnection..ctor(String connectionString) • System.Data.Objects.ObjectContext.CreateEntityConnection( String connectionString) ? System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName) ? Parser.test_workEntities1..ctor() ? C:\proj\Parser\Model1.Designer.cs:строка 34 ? Parser。 BdProvider.InsertAdv() - C:\proj\Parser\BdProvider.cs:строка 28 - TestApp.Program.Main(String[] args) - C:\proj\TestApp\Program.cs:строка 21 - System.
我尝试使用不同的 connectionString 创建 test_workEntities1,但没有成功。
我的连接字符串是
<connectionStrings>
<add name="test_workEntities1"
connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=PKVZALE\SQLEXPRESS;Initial Catalog=test_work;Integrated Security=True;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
</connectionStrings>