views:

112

answers:

2

alt text

Above is the LINQ to SQL designer view for my data context.

Below is the relevant code that the designer generates:

Accessor for the abstract ActivityBase class:

        public System.Data.Linq.Table<ActivityBase> ActivityBases
        {
            get
            {
                return this.GetTable<ActivityBase>();
            }
        }

The ActivityBase class and the list of subclasses:

[Table(Name="dbo.Activities")]
[InheritanceMapping(Code="1", Type=typeof(ActivityBase), IsDefault=true)]
[InheritanceMapping(Code="2", Type=typeof(Project))]
[InheritanceMapping(Code="3", Type=typeof(ProjectActivity))]
[InheritanceMapping(Code="5", Type=typeof(Task))]
[InheritanceMapping(Code="4", Type=typeof(Activity))]
public abstract partial class ActivityBase : INotifyPropertyChanging, INotifyPropertyChanged
{

Is there a way to generate accessor methods for the subclasses as shown in the inheritance mapping above (Project, Task, etc...) without doing it manually? I added them manually but then a change in the designer overwrites any manual changes.

Am i doing this wrong? should I not be making accessors for the sub classes? filtering from ActivityBase seems worse to me.

Thanks for any help on this.

+2  A: 

Notice that LINQ to SQL creates partial classes. If you want to modify the automatically generated classes you can do so by declaring a partial class with the same name and adding the methods there. This way they won't get overwritten when you make a change in the designer.

Mark Byers
I have created my own partial classes but I am also using repository classes where "db = new TaskManagerDataContext()" but I can't use db.Projects because the only accessor is for the Projects parent class of ActivityBase. I was hoping I didnt need to filter my results from db.ActivityBase. Hopefully that makes sense and is there a way I can do this through modifying my partial classes?
Pricey
The accessor is part of my data context class, I have just realised that I need to check if that is also partial (can't till later) if so I can define more accessor methods outside of the designer CS file.
Pricey
A: 

I found this question answers what I wanted to know:

http://stackoverflow.com/questions/936828/what-is-the-cs-file-under-mydatacontext-dbml-for

since the data context is also a partial class I can use that file.

Pricey