Search code examples
c#sqldatabaselinq-to-sqlsqlmetal

C#: Add data to an SQLMetal generated database class?


I used SQLMetal to generate a code file representing my database, and i can't figure out how to add entries to the database from the SQLMetal generated classes. How do i do this? do i just add to the various properties or something?


Solution

  • Here's a good overview of linq-to-sql, which includes how to add to your database via the auto-generated classes (from SQL Metal). Link

    Essentially:

    1. Create your database context object
    2. Create a new object (which was auto-generated)
    3. Populate your object's properties
    4. Add your object to the correct collection within your database context
    5. Submit changes to your database context. Voila!