This project is read-only.

Shopping Cart in LINQ to SQL instead of Entity Framework?

Sep 2, 2011 at 4:06 PM

Hello everyone! Is anybody able to show how would the shopping cart module (Tutorial point #8.) look like adapted to LINQ to SQL instead of Entity Framework? I would be most grateful!

Thank you in advance.

Sep 20, 2011 at 5:35 PM
Edited Sep 20, 2011 at 5:40 PM

First of all I'd like to stress that I'm a beginner.

I've been following a tutorial on how to write a an ASP.NET MVC3 site (by Scott Guthrie). My project is almost finished, all I need are shopping cart and checkout modules. That tutorial doesn't include that but I've found one in MVC Music Store. The only problem is that this MusicStore was based on Entity Framework and my project is based on LINQ to SQL.

I added references to Entity Framework. However when I start the application it throws an error

Partial declarations of 'SklepAlfa.Models.SklepAlfaModelDataContext' must not specify different base classes

(This happens when I add DbContext so it looks like this: public partial class SklepAlfaModelDataContext : DbContext)


Apart from that I get other errors.

public void DodajDoKoszyka(Produkty produkt)
var koszykPrzedmiot = sklepBaza.Koszyk.SingleOrDefault(c => c.id_koszyka == id_koszyka_zakupowego && c.id_produktu == produkt.id_produktu); 
//in this line I get the error quoted below the code

if (koszykPrzedmiot == null)
= new Koszyk
= produkt.id_produktu,
= id_koszyka_zakupowego,
= 1,
= DateTime.Now


Value cannot be null. Parameter name: source

But when I manually add those three tables Koszyk(Cart), Zamowienie(Order), SzczegolyZamowienia(OrderDetails) in Server Explorer and drag them to de designer to my SklepAlfaModel.dbml then I get the following error for each of the variables in those tables:

The type 'SklepAlfa.Models.Koszyk' already contains a definition for 'variable'


Why does it happen? What should I do? Does any of this errors have anything to do with that DbContextmissing? Why can't I use it?