Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I try to explain better using an example:

  • I create the class Product with attibutes like that:

    private string _ProductCode = "";
    [DisplayName("ProductCode")]
    public String ProductCode
    {
       get { return _ProductCode; }
       set { _ProductCode = value; OnPropertyChanged("ProductCode"); }
    }
    
  • the class Product implements the interfaces: INotifyPropertyChanged, IEditableObject

  • I create the class ProductList that has the following property:

    public List<Product> Products { get; set; }
    
  • I bind the class Product in a DataGridView control using the DataSource property

    MyGridView.DataSource = ProductList.Products;
    
  • I have the table ProductListTable on db SqlServer that has more column than the class Product

  • When I push the button "Save" on my form I'd would like to save the ProductList on ProductListTable

I'm really confusing about the way to follow ... I have to use Link 2 Sql, Entity Framework? I'm searching for something simple for a small project, but using POCO classes for rapresenting the data layer.

Now how I should proceed for linking class to DB table?

share|improve this question

migrated from codereview.stackexchange.com Aug 21 '13 at 15:13

This question came from our site for peer programmer code reviews.

    
I guess you are you using WPF, right? –  margabit Aug 21 '13 at 15:14

1 Answer 1

It sounds like Entity Framework is what you want, specifically using the code first techniques.

With code first you're able to create a 'DbContext' class that can hold DbSet<> objects, similar to your List. These DbSets are linked to the database by entity framework and they will take care of the database interaction as long as you call SaveChanges() on them. This method will allow you to keep you POCO objects.

This book: Programming Entity Framework: Code First is great. It'll quickly bring you up to speed (only a few hundred pages).

I'll also add this as quite a full tutorial without buying a book: Code-First Development with Entity Framework 4

share|improve this answer
    
would you mind explaining more on what these resources do and why do you recommend these as answering the question asked? "Link-only answers" are not quite welcome at Stack Exchange –  gnat Dec 13 '13 at 12:00
    
Does that extra paragraph give enough information about EF Code First? Enough that he'd then want to use the links? –  Ben Gale Dec 13 '13 at 12:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.