简体   繁体   English

无法解析EF6.1实体SQL中的表值函数

[英]Can't resolve a Table Valued Function in EF6.1 Entity SQL

I've been spinning my wheels on this for the last couple days and can't pin down what I'm doing wrong. 在过去的几天里,我一直在努力工作,无法确定我做错了什么。 I'm trying to setup a TVF that I can call in esql. 我正在尝试设置可以在esql中调用的TVF。 I started using this as my guide, updating the details to 6.1.1 as needed. 我开始以此为指导,根据需要将详细信息更新为6.1.1。 All my efforts receive a "cannot be resolved into a valid type or function." 我所有的努力都收到了“无法解析为有效的类型或功能”的信息。 I am able to get the results in a Database.SqlQuery result but not in ESQL or Linq. 我能够在Database.SqlQuery结果中获得结果,但不能在ESQL或Linq中获得结果。

Can someone look this over and give me a clue? 有人可以看看这个并给我一个线索吗? I would appreciate it. 我会很感激。

Here is what I have: 这是我所拥有的:

[T-Sql] [T-Sql]

CREATE FUNCTION [Reconciliation].[GetAccountUnits]
(           @PerspectiveId     INT
,           @EffectiveDate     DATETIME
)
RETURNS TABLE
WITH SCHEMABINDING
AS
RETURN
(
    SELECT  [AccountId]     =   V.[AccountId]   
    ,       [PerspectiveId] =   V.[PerspectiveId]
    ,       [Units]         =   V.[Units]
...
)

[StorageModels] [存储模型]

<Function Name="GetAccountUnits" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" Schema="Reconciliation">
  <Parameter Name="PerspectiveId" Type="int" Mode="In"  />
  <Parameter Name="EffectiveDate" Type="datetime" Mode="In" />
  <ReturnType>
    <CollectionType>
      <RowType>
        <Property Name="AccountId" Type="int" Nullable="false" />
        <Property Name="PerspectiveId" Type="int" Nullable="false" />
        <Property Name="Units" Type="decimal" Precision="28" Scale="15" Nullable="false" />
      </RowType>
    </CollectionType>
  </ReturnType>
</Function>

[ConceptualModels] [概念模型]

<EntityContainer>
....
  <FunctionImport Name="GetAccountUnits" IsComposable="true" ReturnType="Collection(MBSA.CARS.Domain.Reconciliation.GetAccountUnits)">
    <Parameter Name="PerspectiveId" Mode="In" Type="Int32" />
    <Parameter Name="EffectiveDate" Mode="In" Type="DateTime" />
  </FunctionImport>
</EntityContainer>
<ComplexType Name="GetAccountUnits">
  <Property Type="Int32" Name="AccountId" Nullable="false" />
  <Property Type="Int32" Name="PerspectiveId" Nullable="false" />
  <Property Type="Decimal" Name="Units" Nullable="false" Precision="28" Scale="15" />
</ComplexType>

[Mappings] [对应]

<FunctionImportMapping FunctionImportName="GetAccountUnits" FunctionName="MBSA.CARS.Domain.Reconciliation.Store.GetAccountUnits" >
  <ResultMapping>
    <ComplexTypeMapping TypeName="MBSA.CARS.Domain.Reconciliation.GetAccountUnits">
      <ScalarProperty Name="AccountId" ColumnName="AccountId" />
      <ScalarProperty Name="PerspectiveId" ColumnName="PerspectiveId" />
      <ScalarProperty Name="Units" ColumnName="Units" />
    </ComplexTypeMapping>
  </ResultMapping>
</FunctionImportMapping>

[Function Stub] [功能存根]

public partial class ReconciliationContext : DomainContext
{
...
    [DbFunction("MBSA.CARS.Domain.Reconciliation.Store", "GetAccountUnits")]
    public virtual IQueryable<GetAccountUnits> GetAccountUnits(int perspectiveId, System.DateTime effectiveDate)
    {
        var perspectiveIdParameter = new ObjectParameter("PerspectiveId", perspectiveId);
        var effectiveDateParameter = new ObjectParameter("EffectiveDate", effectiveDate);

        return ((IObjectContextAdapter)this).ObjectContext.CreateQuery<GetAccountUnits>("[ReconciliationContext].[GetAccountUnits](@PerspectiveId, @EffectiveDate)", perspectiveIdParameter, effectiveDateParameter);
    }
}

I've tried all of these: 我已经尝试了所有这些方法:

[ESQL] [ESQL]

select value it from MBSA.CARS.Domain.Reconciliation.Store.GetDecimalProperty(1, DATETIME'2006-05-31 00:00') As it

select value it from Reconciliation.Store.GetDecimalProperty(1, DATETIME'2006-05-31 00:00') As it

select value it from Reconciliation.GetDecimalProperty(1, DATETIME'2006-05-31 00:00') As it

select value it from ReconciliationContext.GetDecimalProperty(1, DATETIME'2006-05-31 00:00') As it

select value it from GetDecimalProperty(1, DATETIME'2006-05-31 00:00') As it

GetDecimalProperty(1, DATETIME'2006-05-31 00:00')

After digging into the assembly I discovered the ssdl, csdl, and msl embedded resources were out of date. 深入研究程序集后,我发现ssdl,csdl和msl嵌入式资源已过时。 Further investigation revealed that the post build command to generated views had been lost in in source control somewhere along the line. 进一步的调查表明,生成视图的post build命令在源代码管理中一直丢失。 I added them back in rebuilt the project a couple times and now everything is working fine. 我将它们重新添加到重建项目中几次,现在一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM