none
[BUG] Where( x=> x.XXXid = null) will not be translated. RRS feed

  • Question

  •  

    My poco:

     

     

        public partial class PriceSegmentSetDetail
    
        {
    
            public int PriceSegmentSetDetailID { get; set; }
    
            public Nullable<int> PriceSegmentSetID { get; set; }
    
            public Nullable<int> PriceAssignmentDetailID { get; set; }
    
            public Nullable<System.DateTime> InsertDT { get; set; }
    
            public Nullable<int> InsertUserID { get; set; }
    
            public Nullable<System.DateTime> UpdateDT { get; set; }
    
            public Nullable<int> UpdateUserID { get; set; }
    
            public Nullable<int> SegmentGroupID { get; set; }
    
            public Nullable<int> Version { get; set; }
    
    
    
            public virtual PriceAssignmentDetail PriceAssignmentDetail { get; set; }
    
            public virtual MarketingSegmentGroup MarketingSegmentGroup { get; set; }
    
            public virtual PriceSegmentSet PriceSegmentSet { get; set; }
    
        }

     

     

     

    My Query:

    DateTime? comparisonDate = context.PriceSegmentSetDetails
    
    .Where(x => x.PriceAssignmentDetailID != null)
    
    .Max(x => x.InsertDT);

    The sql generated:

     

     

    SELECT 
    
    [GroupBy1].[A1] AS [C1]
    
    FROM ( SELECT 
    
     MAX([Extent1].[InsertDT]) AS [A1]
    
     FROM [dbo].[PriceSegmentSetDetails] AS [Extent1]
    
    )  AS [GroupBy1]

     

     

    Where is the filter in Where clause???

     

    I user Entity Framework 4.2.

     

     

     



    Monday, January 23, 2012 5:26 PM

All replies

  • Hi Ziang;

    I built your table with Code First and then executed your exact query. I completely got a different query sent to and executed on the server and looks correct. Are you sure that the SQL statements is for the query you posted?

    This is the query that was created and sent to the server

    SELECT 
    [GroupBy1].[A1] AS [C1]
    FROM ( SELECT 
    	MAX([Extent1].[InsertDT]) AS [A1]
    	FROM [dbo].[PriceSegmentSetDetails] AS [Extent1]
    	WHERE [Extent1].[PriceAssignmentDetailID] IS NOT NULL
    )  AS [GroupBy1]
    

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Monday, January 23, 2012 6:04 PM
  • Thank you very much for your reply. Can you please try it on EF 4.2? I recently have my framework upgraded from 4.1 and I don't think 4.1 has this issue.

     

    Thanks!

    Monday, January 23, 2012 6:51 PM
  •  

    I was using EF 4.2

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Monday, January 23, 2012 7:01 PM
  • Please add this together with the mappings:
    
    public partial class PriceAssignmentDetail
    {
    public PriceAssignmentDetail()
    {
    this.PriceSegmentSetDetails = new HashSet<PriceSegmentSetDetail>();
    }
     
    public int PriceAssignmentDetailID { get; set; }
    public int PriceAssignmentID { get; set; }
    public decimal PriceChangeAmount { get; set; }
    public Nullable<System.DateTime> EffectiveDate { get; set; }
    public Nullable<System.DateTime> InsertDT { get; set; }
    public Nullable<int> InsertUserID { get; set; }
    public Nullable<System.DateTime> UpdateDT { get; set; }
    public Nullable<int> UpdateUserID { get; set; }
    public int? ProposalID { get; set; }
     
    public virtual ICollection<PriceSegmentSetDetail> PriceSegmentSetDetails { get; set; }
     
    }
    

    modelBuilder.Entity<

    PriceAssignmentDetail

    >()

    .HasKey(x => x.PriceAssignmentDetailID)

    .HasMany(x => x.PriceSegmentSetDetails);

     

    modelBuilder.Entity<

    PriceSegmentSetDetail

    >()

    .HasKey(x => x.PriceSegmentSetDetailID)

    .HasRequired(x => x.PriceAssignmentDetail)

    .WithMany(x => x.PriceSegmentSetDetails);

     

    Monday, January 23, 2012 7:31 PM
  • Hi Ziang;

    In order to better serve you I would request that you zip the project with the issue and place it somewhere on the net where I can download it and test it out. If that is not possible then I would recommend that you create a test project that you can post which also show this issue and post the URL to that download here.

    Thanks


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Monday, January 23, 2012 7:42 PM
  • Hi Ziang,

    How's the problem now?   As Fernado said, we may need some repro project to do further investigation.   You can upload the project at http://skydrive.live.com just with your Windows Live ID. 

    Good day, both!

    Thanks


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, January 24, 2012 8:18 AM
    Moderator
  • Hi,

    Any update?   If you need any further assistance, please feel free to let us know.

    Good day!


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us
    Monday, January 30, 2012 1:54 AM
    Moderator