实体框架不映射调用存储过程的SqlQuery中的2列

实体框架不映射调用存储过程的SqlQuery中的2列,sql,vb.net,entity-framework,stored-procedures,ef-code-first,Sql,Vb.net,Entity Framework,Stored Procedures,Ef Code First,我首先使用代码,试图调用一个存储过程,并将其映射到我的一个类。我创建了一个存储过程BOMComponentChild,它返回一个组件的详细信息,并在PartsPath和MyPath中提供其层次结构的信息。我有一个类用于此存储过程的输出。我遇到了一个问题,除了两列PartsPath和MyPath之外的所有内容都被正确映射,这两个属性最终都是空的。我四处搜索,根据我的理解,映射绕过了任何实体框架名称映射,并使用列名到属性名。名字是一样的,我不知道为什么只有这两列 存储过程的最后一部分是: SELEC

我首先使用代码,试图调用一个存储过程,并将其映射到我的一个类。我创建了一个存储过程BOMComponentChild,它返回一个组件的详细信息,并在PartsPath和MyPath中提供其层次结构的信息。我有一个类用于此存储过程的输出。我遇到了一个问题,除了两列PartsPath和MyPath之外的所有内容都被正确映射,这两个属性最终都是空的。我四处搜索,根据我的理解,映射绕过了任何实体框架名称映射,并使用列名到属性名。名字是一样的,我不知道为什么只有这两列

存储过程的最后一部分是:

SELECT   t.ParentID
        ,t.ComponentID
        ,c.PartNumber
        ,t.PartsPath
        ,t.MyPath
        ,t.Layer
        ,c.[Description]
        ,loc.LocationID
        ,loc.LocationName
        ,CASE WHEN sup.SupplierID IS NULL THEN 1 ELSE sup.SupplierID END AS SupplierID
        ,CASE WHEN sup.SupplierName IS NULL THEN 'Default' ELSE sup.SupplierName END AS SupplierName
        ,c.Active
        ,c.QA
        ,c.IsAssembly
        ,c.IsPurchasable
        ,c.IsMachined
        ,t.QtyRequired
        ,t.TotalQty

FROM    BuildProducts                       t 
        INNER JOIN [dbo].[BOMComponent]     c       ON c.ComponentID    = t.ComponentID         
        LEFT JOIN [dbo].[BOMSupplier]       bsup    ON bsup.ComponentID = t.ComponentID AND bsup.IsDefault = 1
        LEFT JOIN [dbo].[LookupSupplier]    sup     ON sup.SupplierID   = bsup.SupplierID
        LEFT  JOIN [dbo].[LookupLocation]   loc     ON loc.LocationID   = c.LocationID
WHERE 
        (@IsAssembly IS NULL OR IsAssembly = @IsAssembly)
ORDER BY
         t.MyPath
它映射到的类是:

Public Class BOMComponentChild

        Public Property ParentID As Nullable(Of Integer)
        Public Property ComponentID As Integer
        Public Property PartNumber As String
        Public Property MyPath As String
        Public Property PartsPath As String
        Public Property Layer As Integer
        Public Property Description As String
        Public Property LocationID As Integer
        Public Property LocationName As String
        Public Property SupplierID As Integer
        Public Property SupplierName As String
        Public Property Active As Boolean
        Public Property QA As Boolean
        Public Property IsAssembly As Boolean
        Public Property IsPurchasable As Boolean
        Public Property IsMachined As Boolean
        Public Property QtyRequired As Integer
        Public Property TotalQty As Integer

        Public Property Children As IDictionary(Of String, BOMComponentChild) = New Dictionary(Of String, BOMComponentChild)

    End Class
我试着这样称呼它:

Me.Database.SqlQuery(Of BOMComponentChild)("EXEC [BOMComponentChild] @ComponentID, @PathPrefix, @IsAssembly", params).ToList()
当我在ManagementStudio中运行存储过程时,列是正确的且不为null。我就是不明白为什么它们不会映射,因为它们是存储过程中的重要信息。PartsPath和MyPath的类型是varchar(50)

编辑

所以我意识到这些列和其他列之间的唯一区别是它们是用类型转换制作的。我在最后用一个静态字符串替换了它们,它们被正确地映射了。当我用“test”替换最后一个select时,我得到了映射的值。如果我的强制转换在SQL查询中正确显示,那么它有什么问题

;WITH BuildProducts ( ParentID, ComponentID, PartNumber
                    ,PartsPath, MyPath, QtyRequired, TotalQty, Layer)
AS
(
    SELECT   ...
            ,@PathPrefix                        AS PartsPath
            ,CAST(@PathPrefix +  
                    CAST(ComponentID            AS varchar(4))  +
                    '/'                         AS varchar(50)
                  )                             AS MyPath
            ,... 
    FROM    [dbo].[BOMComponent]            
    WHERE   ...

    UNION ALL

    SELECT   ...
            ,CAST(b.PartsPath + 
                    CAST(a.ParentID             AS varchar(4))  +
                    '/'                         AS varchar(50)
                  )                             AS PartsPath
            ,CAST(b.PartsPath + 
                    CAST(a.ParentID             AS varchar(4))  +
                    '/'                                         +
                    CAST(a.ComponentID          AS varchar(4))  +
                    '/'                         AS varchar(50)
                  )                             AS MyPath
            ,...
    FROM    [dbo].[BOMAssembly]             a 
            INNER JOIN [dbo].[BOMComponent] c ON a.ComponentID = c.ComponentID
            ...
)

SELECT  -- t.PartsPath
        --,t.MyPath
        'test' As PartsPath
        ,'test' As MyPath
        ,...

FROM    BuildProducts                       t 
        ...

在我的无限智慧中,我在查询中将参数PathPrefix默认值设置为“/”,但是,我将PathPrefix作为DBNull传入,这与不传入值不同。因此空值通过查询传播

对不起,我浪费了任何人的时间