none
Class Fields Mapping problem on Database.SqlQuery in EF RRS feed

  • General discussion

  • I'm using a class which in not in dbcontext for results. but there is field mapping problem. Count returns true but all fields returns with null value.  Don't understand why EF doesn't map's fields with their values?

    var query = db.Database.SqlQuery<FilterRSTest>(
                           @"
    declare @priceCurrencyID int =1
    declare @LangID int =3
    declare @userID int = 1
    
                            select 
    
    p.ProductCode 
    
     from Products p
    inner join Prices pr on pr.ProductID = p.ID and pr.PriceCurrencyID = @priceCurrencyID
    inner join ProductDetails pd on pd.ProductID = p.ID
    inner join LastVisitedProducts lvp on lvp.ProductID = p.ID and lvp.UserID = @userID
    
    where pd.LangID = @LangID 
    
                    ").ToList();


    Friday, July 12, 2013 3:25 PM

All replies

  • Hi vectorman1;

    The raw SQL you have posted is only returning one column from the database and that would be p.ProductCode. The class FilterRSTest should only contain one property called ProductCode.

    What does FilterRSTest  look like? 

    Are you getting any run time exceptions?

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, July 12, 2013 7:22 PM