none
Only parameterless constructors and initializers are supported in LINQ to Entities.

    Question

  • While trying a sem-complex query to display some ListView content on the page I got stuck on the famous "Only parameterless contstructor and initializers are supported in LINQ to Entities" error.

    Here is the code I used ... I can't find a place where I initialized something inside the query with parameters ....

    protected
     void
     ArtistsList()
    {
        Guid cat1 = new
     Guid("916ec8ae-8336-43b1-87c0-8536b2676560"
    );
        Guid cat2 = new
     Guid("92f2a07f-0570-4521-870a-bf898d1e92d6"
    );
    
        var
     memberOrders = (from
     o in
     DataContext.OrderSet
                            where
     o.Status == 1 || o.Status == 0
                            select
     o.ID);
    
        var
     memberOrderDetails = (from
     o in
     DataContext.OrderDetailSet
                                  where
     memberOrders.Any(f => f == o.Order.ID)
                                  select
     o.Product.ID );
    
        var
     inventoryItems = (from
     i in
     DataContext.InventoryItemSet
                              select
     i.Inventory.Product.ID);
    
        var
     products = (from
     p in
     DataContext.ProductSet
                        join
     m in
     DataContext.ContactSet on
     p.ManufacturerID.Value equals
     m.ID
                        where
     p.Active == true
    
                           && p.ShowOnWebSite == true
    
                           && p.Category.ID != cat1
                           && p.Category.ID != cat2
                           && p.AvailableDate <= DateTime.Today
                           && (p.DiscontinuationDate == null
     || p.DiscontinuationDate >= DateTime.Today)
                           && memberOrderDetails.Any(f => f != p.ID)
                           && inventoryItems.Any(f => f == p.ID)
                        select
     new
     { ContactID = m.ID, ContactName = m.Name });
    
        artistsRepeater.DataSource = products;
        artistsRepeater.DataBind();
    
        Response.Write("PRODUCT COUNT: "
     + products.Count());
    }
    
    

    The error itself pops on the line artistsRepeater.DataSource = products;

    I tried to comment the lines && memberOrderDetails.Any(f => f != p.ID) and && inventoryItems.Any(f => f == p.ID) , still doesn't change anything

     

    I found out also that if I remove the "join" part the error is no longer there (but obviously it's not the right informations that comes out since I need data from the ContactSet).

     

    Any hints ?

     

    [edit]

    With LINQpad, it works with the join but with it is bugging on the commented line

    (from p in Products
    join m in Members on p.ManufacturerID.Value equals m.ID
    where p.Active == true
    && p.ShowOnWebSite == true
    && p.AvailableDate <= DateTime.Today
    && (p.DiscontinuationDate == null || p.DiscontinuationDate >= DateTime.Today)
    //&& (from od in MemberOrderDetails where (from mo in MemberOrders where mo.Status == 1 || mo.Status == 0 select mo.ID).Any(f => f == od.ID) select od.Product.ID)
    && (from inv in InventoryItems select inv.Inventory.ProductID).Any(i => i.Value == p.ID)
    select m).Distinct()
    

    • Edited by Erick.Girard Tuesday, January 19, 2010 8:43 PM adding some more details
    Tuesday, January 19, 2010 7:39 PM

Answers

  • I finally achieved to "nail" the problem. So basically I rewrote the template page. Before I had a ListView inside a ListView inside another ListView (pretty crazy actually, I had to work with someone else's work). I finally used a Repeater inside a Listview and worked perfectly with that.
    Monday, January 25, 2010 5:04 PM

All replies

  • Hello,

    If it is convenient, could you please send me a demo project and db file to repro this problem?   I will do my best to help.  My mail address is v-micsun @ microsoft.com (remove the spaces besides @).

    Have a nice day!


    Best Regards,
    Lingzhi Sun
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, January 25, 2010 2:44 PM
  • I finally achieved to "nail" the problem. So basically I rewrote the template page. Before I had a ListView inside a ListView inside another ListView (pretty crazy actually, I had to work with someone else's work). I finally used a Repeater inside a Listview and worked perfectly with that.
    Monday, January 25, 2010 5:04 PM