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,
     };

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Why does my wifi fail to stay connected?

분류에서Dev

Why does testing for instanceOf in my unit tests fail?

분류에서Dev

Why does Doctrine QueryBuilder destroy my query?

분류에서Dev

Why is my SQL "INSERT INTO" query not working?

분류에서Dev

LinQ in C#, why does query sentence must convert to tolist()?

분류에서Dev

Why does `grep fil*` fail?

분류에서Dev

Why does bacula restore fail?

분류에서Dev

Why does `xdg-mime query filetype ...` fail to find a new added file type?

분류에서Dev

Convert this SQL query into Linq

분류에서Dev

Why is my VBA/SQL query say I am missing an operator?

분류에서Dev

Why does Chocolatey fail to install Elixir on Windows?

분류에서Dev

how to change sql query to linq?

분류에서Dev

Why does LINQ throw a NotSupportedException?

분류에서Dev

why my paypal api call fail with error Version is not supported?

분류에서Dev

Why do object arrays in my ArrayList fail to retain their values?

분류에서Dev

Why does ternary operator fail with a type mismatch error?

분류에서Dev

Why does INSERT INTO fail with 'Operand should contain 1 column(s)'?

분류에서Dev

Why does this applescript that tasks to iTunes sometimes fail with -1712

분류에서Dev

Why does `exec 2>&1` fail in this bourne shell script?

분류에서Dev

Why does the first access to samba shared folder always fail?

분류에서Dev

Linq to Sql query with multiple row subquery

분류에서Dev

How to GroupBy data in Linq to SQL query

분류에서Dev

Linq to Entities: Parameterised Raw Sql query?

분류에서Dev

Linq to sql query not returning correct items

분류에서Dev

LINQ to SQL query with multiple contained strings

분류에서Dev

SQL query does not update table

분류에서Dev

Why does this MySQL XOR query return 0?

분류에서Dev

error in my SQL syntax in GetCountry query

분류에서Dev

Angular: Why does my formArray not validate or update?

Related 관련 기사

  1. 1

    Why does my wifi fail to stay connected?

  2. 2

    Why does testing for instanceOf in my unit tests fail?

  3. 3

    Why does Doctrine QueryBuilder destroy my query?

  4. 4

    Why is my SQL "INSERT INTO" query not working?

  5. 5

    LinQ in C#, why does query sentence must convert to tolist()?

  6. 6

    Why does `grep fil*` fail?

  7. 7

    Why does bacula restore fail?

  8. 8

    Why does `xdg-mime query filetype ...` fail to find a new added file type?

  9. 9

    Convert this SQL query into Linq

  10. 10

    Why is my VBA/SQL query say I am missing an operator?

  11. 11

    Why does Chocolatey fail to install Elixir on Windows?

  12. 12

    how to change sql query to linq?

  13. 13

    Why does LINQ throw a NotSupportedException?

  14. 14

    why my paypal api call fail with error Version is not supported?

  15. 15

    Why do object arrays in my ArrayList fail to retain their values?

  16. 16

    Why does ternary operator fail with a type mismatch error?

  17. 17

    Why does INSERT INTO fail with 'Operand should contain 1 column(s)'?

  18. 18

    Why does this applescript that tasks to iTunes sometimes fail with -1712

  19. 19

    Why does `exec 2>&1` fail in this bourne shell script?

  20. 20

    Why does the first access to samba shared folder always fail?

  21. 21

    Linq to Sql query with multiple row subquery

  22. 22

    How to GroupBy data in Linq to SQL query

  23. 23

    Linq to Entities: Parameterised Raw Sql query?

  24. 24

    Linq to sql query not returning correct items

  25. 25

    LINQ to SQL query with multiple contained strings

  26. 26

    SQL query does not update table

  27. 27

    Why does this MySQL XOR query return 0?

  28. 28

    error in my SQL syntax in GetCountry query

  29. 29

    Angular: Why does my formArray not validate or update?

뜨겁다태그

보관