views:

199

answers:

2

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?

A: 

The generated classes are partial classes, so you can extend them anywhere else in your assembly with another partial class definition (note: I don't mean extension methods, just another partial class declaration).

That way, you can also re-generate those classes without worrying of overwriting your other extensions of the classes.

Alex
+1  A: 

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!
Pwninstein