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.
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] 삭제
몇 마디 만하겠습니다