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
2009-08-30 05:35:47
+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:
- Create your database context object
- Create a new object (which was auto-generated)
- Populate your object's properties
- Add your object to the correct collection within your database context
- Submit changes to your database context. Voila!
Pwninstein
2009-08-30 05:42:49