Why does my linq to sql query fail?

mryoyo

I am new to .Net (and stackoverflow) so I am running into a few problems. One vexing problem is this linq query below. Some information about the code. CustomerCart is a separate Model class in my project where the products member is a list of products. If I remove the products from the select new CustomerCart portion it runs fine and the data is present. So I figure it is my syntax. Can I not put a linq statement inside an assignment constructor? Any help would be appreciative. Thank you in advance.

var k = from s in store.Customers
        join p in store.ShoppingCarts on s.custId equals p.customerId
        select new CustomerCart()
        {
            FirstName = s.firstName,
            LastName = s.lastName,
            products = (from j in store.Products
                        where p.productId == j.productId
                        select j).ToList(),
            CartID = p.cartId,
            CustomerID = s.custId,
         };

**Edit Error I receive: The model item passed into the dictionary is of type 'System.Data.Objects.ObjectQuery`1[productShop.Models.CustomerCart]', but this dictionary requires a model item of type 'productShop.Models.CustomerCart'.

Sorry for not placing the error message with my question.

Enigmativity

Try this query instead:

var k =
    from s in store.Customers
    join p in store.ShoppingCarts on s.custId equals p.customerId
    join j in store.Products on p.productId equals j.productId into products
    select new CustomerCart()
    {
        FirstName = s.firstName,
        LastName = s.lastName,
        products,
        CartID = p.cartId,
        CustomerID = s.custId,
     };

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Why does assembly binding fail in my project?

From Dev

Why does this LinQ query not like chars?

From Dev

Why does this SQL query fail

From Dev

Why does my cross-compiling fail?

From Dev

Why does Linq ignore my where clause?

From Dev

Why does my redirected CORS request fail?

From Dev

Why query does not fail with nonexistent column in subquery?

From Dev

getting my SQL query to be displayed in LINQ form

From Dev

Why does my connection to cloud sql from local php app engine development fail using ipv6?

From Dev

Why does mongoexport query with $exist fail?

From Dev

Why does CodeIgniter return my SQL query as an array, with an object inside?

From Dev

Why does my query return no records inside a program (PL/SQL), but does when ran manually in SQL?

From Dev

Why does my rspec test fail?

From Dev

Why does my query return no records inside a program (PL/SQL), but does when ran manually in SQL?

From Dev

Why does my kernel fail to build?

From Dev

if my join fails, it seems to fail the linq query in its entirety

From Dev

Why does my NSMutableURLRequest fail?

From Dev

Why does my pointer arithmetic fail in this array

From Dev

Why does my wifi fail to stay connected?

From Dev

LINQ equivalent of my SQL Query for UNION ALL

From Dev

Why does my connection to cloud sql from local php app engine development fail using ipv6?

From Dev

Why does my jasmine tests fail on this directive?

From Dev

Why does my LINQ query always return 0?

From Dev

Why does my Vapor query always fail?

From Dev

Why does my SQL query return no rows, when sum is 0

From Dev

Why does this linq query fail when I change the select clause to select new Model

From Dev

Why does the LINQ query return no element?

From Dev

Why Does My FAMILY Query Fail?

From Dev

Why does this Linq Query Return Different Results than SQL Equivalent?

Related Related

  1. 1

    Why does assembly binding fail in my project?

  2. 2

    Why does this LinQ query not like chars?

  3. 3

    Why does this SQL query fail

  4. 4

    Why does my cross-compiling fail?

  5. 5

    Why does Linq ignore my where clause?

  6. 6

    Why does my redirected CORS request fail?

  7. 7

    Why query does not fail with nonexistent column in subquery?

  8. 8

    getting my SQL query to be displayed in LINQ form

  9. 9

    Why does my connection to cloud sql from local php app engine development fail using ipv6?

  10. 10

    Why does mongoexport query with $exist fail?

  11. 11

    Why does CodeIgniter return my SQL query as an array, with an object inside?

  12. 12

    Why does my query return no records inside a program (PL/SQL), but does when ran manually in SQL?

  13. 13

    Why does my rspec test fail?

  14. 14

    Why does my query return no records inside a program (PL/SQL), but does when ran manually in SQL?

  15. 15

    Why does my kernel fail to build?

  16. 16

    if my join fails, it seems to fail the linq query in its entirety

  17. 17

    Why does my NSMutableURLRequest fail?

  18. 18

    Why does my pointer arithmetic fail in this array

  19. 19

    Why does my wifi fail to stay connected?

  20. 20

    LINQ equivalent of my SQL Query for UNION ALL

  21. 21

    Why does my connection to cloud sql from local php app engine development fail using ipv6?

  22. 22

    Why does my jasmine tests fail on this directive?

  23. 23

    Why does my LINQ query always return 0?

  24. 24

    Why does my Vapor query always fail?

  25. 25

    Why does my SQL query return no rows, when sum is 0

  26. 26

    Why does this linq query fail when I change the select clause to select new Model

  27. 27

    Why does the LINQ query return no element?

  28. 28

    Why Does My FAMILY Query Fail?

  29. 29

    Why does this Linq Query Return Different Results than SQL Equivalent?

HotTag

Archive