开发者

Unable to construct an entity (complex) object from a query

Hey, I am very new to entity, sql, c#, and asp.net so this might be something easily fixed.

I am attempting to display all the inactive products stored in my table called products in a datagrid.

var productQuery = from b in solutionContext.Version
                   where b.Product.Name == search && b.Product.ActiveNumber > b.VersionNumber
                   select new Product
                   {
                                   Name = b.Product.Name,
                                   Description = b.Product.Description,
                                   ID = b.ID,
                                   LastNumber = b.Product.LastNumber,
                                   MiddleNumber = b.Product.MiddleNumber开发者_运维百科,
                                   RSTATE = b.RSTATE,
                                   ActiveNumber = b.Product.ActiveNumber,
                                   LastModified = b.Product.LastModified,
                                   ParentID = b.Product.ParentID,
                                   ProductType = b.Product.ProductType
                  };

                  ProductsGrid.DataSource = productQuery;
                  ProductsGrid.DataBind();

I am getting this error:

  • $exception {"The entity or complex type 'SolutionsModel.Product' cannot be constructed in a LINQ to Entities query."} System.Exception {System.NotSupportedException}

Thanks for any advice!


The error is saying that you cannot generate a LINQ to Entities object of type Product. But you can return it. Can you try to return b.Product that might work correctly?

var productQuery = from b in solutionContext.Version
                   where b.Product.Name == search && b.Product.ActiveNumber > b.VersionNumber
                   select b.Product; 

                  ProductsGrid.DataSource = productQuery;
                  ProductsGrid.DataBind();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜