views:

86

answers:

3

Hello,

I'm new to Linq and Visual web developer 2008 Express. I have read some posts here and Scott Guthrie's on setting up Linq, but I'm a little stuck because the classes aren't auto-generating as I thought they would. I have setup a database with a simple table (with the Primary Key as the ID, and it is set to auto-increment) plus a few other columns, and dragged and dropped it on to the dbml linq designer pane. The table appears in the window, but no classes are auto-generated. When I right click on the table and select "View Code", DataClasses.cs is displayed, but I only see a partial class with no methods or properties.

Isn't Linq supposed to do this, or have I (quite likely) missed the point completely? Or is this functionality not available in Visual Web Developer 2008 Express?

Any help you can provide would be appreciated :)

Thanks!

+1  A: 

No, you're not missing anything. That is exactly how it should work. Go to solution explorer, expand the dbml, and double-click on whatever.designer.cs. Down at the bottom, you'll see ...

[Table(Name="dbo.YourTable")]
public partial class YourTable: INotifyPropertyChanging, INotifyPropertyChanged
{

 private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

... and all of your properties.

Rap
Thank you - everything is there :)
Hewie
A: 

As mentioned, LINQ-To-SQL will not actually generate individual class files for you - if you go and write some code that references a class for one of your tables, you will find that it is there...

Paddy
Thanks - I expected to see a stack of class files generated, but I can see that the classes are accessible anyway :)
Hewie
+1  A: 

As the other answerers have already pointed out, you do get your code generated - into a single (modelname).designer.cs file.

This may or may not be what you expected and wanted - if you can live with it - perfect!

If not, there's at least one set of Code generation templates out there called PLINQO which are based on CodeSmith, the well known code generator. Those templates allow you to do a lot of things standard Linq-to-SQL doesn't support:

  • generate classes for each table into their own, single file in a user-definable folder
  • actually update your DBML model and all associated generated classes if the underlying database changes
  • adds a "(entityname)Manager" class to manage entities of a given type (like Customer etc.)

All in all, it's quite a neat solution to handle Linq-to-SQL code generation. Excellent stuff - recommended!

Marc

marc_s