Entity Framework does not map 2 columns from a SqlQuery calling a stored procedure

Posted by user1783530 on Stack Overflow See other posts from Stack Overflow or by user1783530
Published on 2012-10-29T16:58:11Z Indexed on 2012/10/29 17:00 UTC
Read the original article Hit count: 180

I'm using Code First and am trying to call a stored procedure and have it map to one of my classes. I created a stored procedure, BOMComponentChild, that returns details of a Component with information of its hierarchy in PartsPath and MyPath. I have a class for the output of this stored procedure. I'm having an issue where everything except the two columns, PartsPath and MyPath, are being mapped correctly with these two properties ending up as Nothing. I searched around and from my understanding the mapping bypasses any Entity Framework name mapping and uses column name to property name. The names are the same and I'm not sure why it is only these two columns.

The last part of the stored procedure is:

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 'Scinomix' 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

and the class it maps to is:

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

I am trying to call it like this:

Me.Database.SqlQuery(Of BOMComponentChild)("EXEC [BOMComponentChild] @ComponentID, @PathPrefix, @IsAssembly", params).ToList()

When I run the stored procedure in management studio, the columns are correct and not null. I just can't figure out why these won't map as they are the important information in the stored procedure. The types for PartsPath and MyPath are varchar(50).

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about entity-framework