1

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?

Mark Carpenter
  • 17,445
  • 22
  • 96
  • 149
RCIX
  • 38,647
  • 50
  • 150
  • 207

2 Answers2

1

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
  • 75,813
  • 86
  • 255
  • 348
1

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!
Mark Carpenter
  • 17,445
  • 22
  • 96
  • 149