Reputation: 2017
I have my database (called "Starship") and I generate LinqToSql Entity Classes and Data Context with designer. As an output, i got Starship.dbml
file with 2 sub-files:
Starship.dbml.layout
Starship.designer.cs
The problem is that I found that the designer generated my Entity classes and Data Context within this single file: Starship.designer.cs
:
[global::System.Data.Linq.Mapping.DatabaseAttribute(Name="Starship")]
public partial class StarshipDataContext : System.Data.Linq.DataContext
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Roles")]
public partial class Role : INotifyPropertyChanging, INotifyPropertyChanged
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Sections")]
public partial class Section : INotifyPropertyChanging, INotifyPropertyChanged
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.CrewMembers")]
public partial class CrewMember : INotifyPropertyChanging, INotifyPropertyChanged
Well, I always thought that keeping single file for single class is a good practice, so why those classes are in the same file? I guess that if the database consisted of about 20 tables, this would be huge file. Is there any way of generating them in separate files?
Upvotes: 1
Views: 286
Reputation: 7830
As far as i know, there is no option in VS to tell the ORM-Designer to generate the classes in a separate files. It is easier to put them all in one file. You can manually extract the classes to files and still use them normally.
Upvotes: 1
Reputation: 11964
Single file for single class is good practice when you need to read and update this class code. For generated code this is not important. Usual you should not look in this files, but look on model layout instead. In another hand, generate it in single file is simpler than in many files.
Upvotes: 1