none
Insert data in database? Wpf application and Mvvm RRS feed

  • Question

  • Hi all,

    I have for example three tables in database
    first table Person: (Id, firstname,lastname, address, phonenumber)
    second table Role: (Id, title, description)
    third table Members (Id, institution, description)
    I added LinqToSqlClass in my project solution, and for each table I created class with get&set property and implemented INotifyPropertyChanged (this is a model layer). How to create method for insert data in my database using linq to sql? Thanks
    Tuesday, December 28, 2010 11:48 PM

Answers

  • How you use LINQ is the same regardless of your design pattern. Are you really asking the most basic of questions: how to use LINQ?

    Your model's method creates a data context object and a Person object. You populate your person object, then add it to the data context object and finally submit your changes.

    If that's still too high level then you need to understand a little of the csharp/vb file associated with the dbml. It declares a class (usually by default DataClassesDataContext) which inherits from LINQ's DataContext class. It also defines one class per table (e.g. Person).

    Friday, January 7, 2011 9:12 AM

All replies

  • Why are you trying to handcraft this? There are two commonly used tools which create the code for you: Visual Studio's O/R Designer and SqlMetal. I have only used the former but I know many like SqlMetal.

    Wednesday, December 29, 2010 1:43 PM
  • Ok, but how  can I  resolve my problem? I added .dbml file, but I have problem  inserting data in database. How can I do it, but on other side, to follow rules mvvm pattern? 
    Wednesday, December 29, 2010 5:59 PM
  •  Answer like a NewYear gift :-) 24:02:36
    Thursday, December 30, 2010 10:58 PM
  • How you use LINQ is the same regardless of your design pattern. Are you really asking the most basic of questions: how to use LINQ?

    Your model's method creates a data context object and a Person object. You populate your person object, then add it to the data context object and finally submit your changes.

    If that's still too high level then you need to understand a little of the csharp/vb file associated with the dbml. It declares a class (usually by default DataClassesDataContext) which inherits from LINQ's DataContext class. It also defines one class per table (e.g. Person).

    Friday, January 7, 2011 9:12 AM