我试图通过模型浏览器添加存储过程,SP有一个表值参数.SP添加了函数导入,但它缺少表值参数.SP有5个参数,包括tvp,但我只能看到4参数和tvp参数丢失.
我用Google搜索找到原因和解决方案.每个人都建议使用权限的ExecuteStoreProcedure方法.例如,实体框架存储过程表值参数
但我想使用在我们使用模型浏览器添加SP时创建的函数import,所有其他SP运行良好,因为它们没有tvp.注意:使用EF 6.1.1和.net 4.5以及VS2013
Quetion:C#和EF是否支持通过TVP导入SP?
以下有何不同之处
CreateQuery() ExecuteFunction(), ExecuteStoreQuery() and ExecuteStoreCommand()
Run Code Online (Sandbox Code Playgroud)
据我所知,CreateQuery用于Entity SQL,其余的方法用于在DB中定义的sql函数或存储过程.
根据ObjectContext类元数据,它们如下:
CreateQuery():Creates an System.Data.Objects.ObjectQuery<T> in the current object context by using the specified query string.
Returned -> System.Data.Objects.ObjectQuery<T>
ExecuteFunction(): Executes a stored procedure or function that is defined in the data source and expressed in the conceptual model; discards any results returned from
the function; and returns the number of rows affected by the execution.
Returned -> The number of rows affected.
This has an overloaded version which return -> The entity …Run Code Online (Sandbox Code Playgroud) 我想我目前在 Entity Framework 6 和可能的 ADO.NET 中遇到错误。由于有截止日期,我不确定我可以等待修复此错误,希望有人可以帮助我解决问题。
问题是查询在应该是 0.01 和 0.05 的地方使用了值 1 和 5。然而奇怪的是 0.1 似乎正在工作
当前生成的查询是:(从 SQL Server Profiler 获取)
declare @p3 dbo.someUDT
insert into @p3 values(NULL,5)
insert into @p3 values(5,0.10)
insert into @p3 values(NULL,1)
insert into @p3 values(1,2)
exec sp_executesql N'Select * from @AName',N'@AName [dbo].[someUDT] READONLY',@AName=@p3
Run Code Online (Sandbox Code Playgroud)
虽然正确的代码是:
declare @p3 dbo.someUDT
insert into @p3 values(NULL,0.05)
insert into @p3 values(0.05,0.10)
insert into @p3 values(NULL,0.01)
insert into @p3 values(0.01,0.02)
exec sp_executesql N'Select * from @AName',N'@AName [dbo].[someUDT] READONLY',@AName=@p3
Run Code Online (Sandbox Code Playgroud)
我已经在 github 上创建了一个问题: …
c# ado.net entity-framework user-defined-types entity-framework-6
我在 SQL Server 中有一个用户定义的函数,它接受 TVP(表值参数)作为参数。在 EF 中,如何从 C# 调用这样的函数?
我尝试使用该方法,ObjectContext.CreateQuery<>但出现以下错误:
函数“QueryByParam”的参数“param”无效。参数只能是可以转换为 Edm 标量类型的类型。
也尝试过方法ObjectContext.ExecuteStoreQuery<>并得到相同的错误。IQueryable无论如何它都不会返回。
示例代码
[DbFunction(nameof(SampleDbContext), "QueryByParam")]
public IQueryable<SecurityQueryRow> QueryByParam(IEnumerable<ProfileType> profiles, bool isActive = false)
{
DataTable dataTable = ....
ObjectParameter profilesParam = new ObjectParameter("profileTypeIds", dataTable);
ObjectParameter isActiveParam = new ObjectParameter("isActive ", isActive);
return ((IObjectContextAdapter)this).ObjectContext.CreateQuery<SecurityQueryRow>(
string.Format("[{0}].[{1}](@profileTypeIds, @isActive)", GetType().Name, "QueryByParam"),
profilesParam,
isActiveParam);
}
Run Code Online (Sandbox Code Playgroud)
要求是我们需要一个 IQueryable 返回,而不是消耗的结果。
c# sql-server entity-framework table-valued-parameters entity-framework-6
我在SQL Server 2008中有一个名为"GetPrices"的存储过程,其中有一个名为"StoreIDs"的表值参数.
这是我为这个TVP创建的类型:
CREATE TYPE integer_list_tbltype AS TABLE (n int)
Run Code Online (Sandbox Code Playgroud)
我想从我的实体框架中调用SP.但是当我尝试将存储过程添加到EDM时,我收到以下错误:
函数'GetPrices'在参数索引2处具有参数'StoreIDs',其具有不受支持的数据类型'表类型'.该功能被排除在外.
这有什么解决方法吗?有什么想法吗?
法比奥
sql-server stored-procedures sql-server-2008 table-valued-parameters entity-framework-4
我有一个带有表值参数的存储过程。我必须从 .net 核心中的实体框架调用它。
我在上下文对象上找不到任何 API。
我曾尝试使用 ADO.net API 并且它有效,但现在我必须从 .net 核心中的 EF 调用它。我必须调用返回结果的存储过程,我必须捕获它。
我的示例 SP 如下
CREATE PROCEDURE [dbo].[GetMyData]
@MyRequest [dbo].[MyRequestType] Readonly
As
BEGIN
--Its sample SP thats why returned request table as it is
select * from @MyRequest
END
Run Code Online (Sandbox Code Playgroud)
MyRequestType 是用户定义的表类型
它的结构如下
CREATE TYPE [dbo].[MyRequestType] AS TABLE(
[Id] [numeric](22, 8) NULL,
[Col1] [bigint] NULL,
[Col2] [numeric](22, 8) NULL
)
Run Code Online (Sandbox Code Playgroud)
我在 EF 核心中使用代码优先方法
任何帮助将不胜感激。