我尝试使用一些实体框架和一些旧的DataSet创建应用程序,但我只使用实体的动态连接字符串,并且需要在运行时删除元数据以创建到我的数据库的连接字符串.任何人都知道从Entity Framework Connection中删除所有元数据的方法
我有这个
Metadata=res://*/Models.SiteModel.csdl|res://*/Models.SiteModel.ssdl|res://*/Models.SiteModel.msl;provider=System.Data.sqlClient;provider connection string="Data Source=(local);Initial Catalog=MyDB;Persist Security Info=True;User ID=sa;Password=P@ssw0rd;MultipleActiveResultSets=True"
并且只需要这个:
Data Source=(local);Initial Catalog=MyDB;Persist Security Info=True;User ID=sa;Password=P@ssw0rd;MultipleActiveResultSets=True
您可以使用EntityConnectionStringBuilder类:
string connectionString = "Metadata=res://*/Models.SiteModel.csdl|res://*/Models.SiteModel.ssdl|res://*/Models.SiteModel.msl;provider=System.Data.sqlClient;provider connection string=\"Data Source=(local);Initial Catalog=MyDB;Persist Security Info=True;User ID=sa;Password=P@ssw0rd;MultipleActiveResultSets=True\""; EntityConnectionStringBuilder builder = new EntityConnectionStringBuilder(connectionString); builder.Metadata = null; connectionString = builder.ConnectionString;