vb.net 参数“xmlReader”无效。必须至少提供一个 .ssdl 工件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26891571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 18:27:35  来源:igfitidea点击:

Argument 'xmlReader' is not valid. A minimum of one .ssdl artifact must be supplied

c#vb.netentity-frameworkado.net

提问by Vahid Farahmandian

I have a class that is going to execute entity framework based queries. this class is a general class and is DbContext independent class(I mean there is no ssdl or semiliar files). in this class I am going to execute raw sql queries too. in order to this I add a method like:

我有一个类将执行基于实体框架的查询。这个类是一个通用类,是 DbContext 独立类(我的意思是没有 ssdl 或 semiliar 文件)。在这门课中,我也将执行原始 sql 查询。为此,我添加了一个方法,如:

 Return _dbContext.Database.SqlQuery(Of String)(query).FirstOrDefault()

to execute scalars. but there is an error in this stage that says:

执行标量。但是在这个阶段有一个错误说:

Additional information: Argument 'xmlReader' is not valid. A minimum of one .ssdl artifact must be supplied.

when I was going to create new instance of DbContext, I had passed this connection string to it:

当我要创建 DbContext 的新实例时,我已将这个连接字符串传递给它:

metadata=res://*;provider=System.Data.SqlClient;provider connection string="Data Source=.;Initial Catalog=MyDb;integrated security=true;

Error Detail:

错误详情:

System.ArgumentException was unhandled by user code
HResult=-2147024809
Message=Argument 'xmlReader' is not valid. A minimum of one .ssdl artifact must be supplied. 
Source=EntityFramework
StackTrace:
   at System.Data.Entity.Core.EntityUtil.CheckArgumentEmpty[T](IEnumerable`1& enumerableArgument,  Func`2 errorMessage, String argumentName)
   at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection..ctor(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths)
   at System.Data.Entity.Core.Metadata.Edm.MetadataCache.LoadStoreCollection(EdmItemCollection edmItemCollection, MetadataArtifactLoader loader)
   at System.Data.Entity.Core.Metadata.Edm.MetadataCache.<>c__DisplayClass5.<>c__DisplayClass7.<GetMetadataWorkspace>b__1()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Lazy`1.get_Value()
   at System.Data.Entity.Core.Metadata.Edm.MetadataCache.<>c__DisplayClass5.<>c__DisplayClass7.<GetMetadataWorkspace>b__4()
   at System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.LoadAndCheckItemCollection[T](Func`1 itemCollectionLoader)
   at System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.<>c__DisplayClass16.<.ctor>b__f()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Lazy`1.get_Value()
   at System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.GetItemCollection(DataSpace dataSpace, Boolean required)
   at System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.GetItemCollection(DataSpace dataSpace)
   at System.Data.Entity.Core.Objects.ObjectContext.InitializeMappingViewCacheFactory(DbContext owner)
   at System.Data.Entity.Core.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor, ObjectQueryExecutionPlanFactory objectQueryExecutionPlanFactory, Translator translator, ColumnMapFactory columnMapFactory)
   at System.Data.Entity.Core.Objects.ObjectContext..ctor(EntityConnection connection)
   at System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel()
   at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel()
   at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
   at System.Data.Entity.Internal.InternalContext.Initialize()
   at System.Data.Entity.Internal.LazyInternalContext.get_ObjectContext()
   at System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery[TElement](String sql, Nullable`1 streaming, Object[] parameters)
   at System.Data.Entity.Internal.InternalContext.ExecuteSqlQueryAsIEnumerator[TElement](String sql, Nullable`1 streaming, Object[] parameters)
   at System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery(Type elementType, String sql, Nullable`1 streaming, Object[] parameters)
   at System.Data.Entity.Internal.InternalSqlNonSetQuery.GetEnumerator()
   at System.Data.Entity.Infrastructure.DbRawSqlQuery`1.GetEnumerator()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
   at IdeaDataAccess.EF.EntityFrameworkQueryPerformer`1.ExecuteScalar(String query)
   at IdeaBusiness.DatabaseCore.Core`2.ExecuteScalar(String query)
   at IdeaBusiness.DatabaseCore.Facade.ExecuteScalar(String query)
   at IdeaComponent.IdeaComponent.IdeaGridView.OnRowCreated(GridViewRowEventArgs e) in D:\Solutions\IdeaCenter\Source Code\IdeaCenterV2\IdeaComponent\Components\GridView\IdeaGridView.vb:line 515
   at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource)
   at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
   at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
   at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data)
   at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
   at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
   at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
   at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
   at System.Web.UI.WebControls.GridView.DataBind()
   at WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in C:\Users\idea\Desktop\New folder\WebForm1.aspx.vb:line 8
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   InnerException: 

回答by Vahid Farahmandian

I finally find a solution for this problem. I added a reference to EntityFramework.dll in my UI and then pass typical connection string to my Biz layer and create a DbContext object based on this, thus executing functions in DataAccess done with no error. Thank you for all. If you need to know more about my solution, please tell me to illustrate it

我终于找到了解决这个问题的方法。我在我的 UI 中添加了对 EntityFramework.dll 的引用,然后将典型的连接字符串传递给我的 Biz 层并基于此创建一个 DbContext 对象,从而在 DataAccess 中执行函数而没有错误。感谢你所做的一切。如果您需要更多地了解我的解决方案,请告诉我来说明它

回答by simon at rcl

Looking at your Connection String, it looks a bit lacking. This is one from a current project, with various linebreaks added to make it easier to read:

看看你的连接字符串,它看起来有点缺乏。这是来自当前项目的一个,添加了各种换行符以使其更易于阅读:

          <connectionStrings>
             <add name="PowerDespatchConnection" 
    connectionString="

metadata=res://*/PowerDespatch.csdl|
         res://*/PowerDespatch.ssdl|
         res://*/PowerDespatch.msl;
         provider=System.Data.SqlClient;
provider connection string=&quot;data source=athena;initial catalog=RCDev;Integrated Security=SSPI;App=EntityFramework&quot;
           " 
providerName="System.Data.EntityClient" />

You are missing the csdl, ssdl, and msl sections. (PowerDespatch is the name of the Model.) You should find the matching files under your EF project folder, in obj\Debug\edmxResourcesToEmbed.

您缺少 csdl、ssdl 和 msl 部分。(PowerDespatch 是模型的名称。)您应该在 EF 项目文件夹下的 obj\Debug\edmxResourcesToEmbed 中找到匹配的文件。

If these are missing, then something about how you created the Model is not right.

如果缺少这些,那么关于您如何创建模型的某些内容是不正确的。