Is it possible for a LINQ to SQL discriminator column to be non-inheriting?

I’m working on a database and LINQ to SQL web app using ASP.NET. My setup includes two types of pages: standard and root. The database has separate tables for Page and RootPage:

Page Table:
- PageId (PK)
- HtmlTitle
- PageHeading
- MetaDescription
- IsRoot

RootPage Table:
- PageId (FK, PK)
- FavIcon
- StyleSheet
- MasterPage

I’ve set the IsDiscriminator property for the IsRoot column in my DBML file. I’m hoping this will make the RootPage class inherit from Page.

What I want to do is something like this:

var roots = db.Pages.OfType<RootPage>();

// Or

RootPage newRoot = new RootPage {
    HtmlTitle = "Home",
    FavIcon = "main.ico"
};
db.Pages.Add(newRoot);
db.SaveChanges();

My question is: Can the IsDiscriminator column be nullable or false? Will this setup work as expected?

hey, i’ve used linq to sql before and ur setup looks alright. but discriminator columns usually cant be nullable, it might mess up inheritance. try using a non-nullable int column than bool? like pageType=1 for normal, pageType=2 for root. that way u can add more types if needed

While your approach is on the right track, there are a few considerations to keep in mind with LINQ to SQL discriminators. Typically, the discriminator column should be non-nullable to ensure proper inheritance mapping. Having it nullable or set to false could lead to unexpected behavior during querying and object instantiation.

Instead of using IsRoot as a discriminator, consider a more explicit approach. Creating a PageType column in the Page table with values such as ‘Standard’ and ‘Root’ would offer clearer separation and allow for future expansion as needed.

For your use case, exploring Table-Per-Type (TPT) inheritance in Entity Framework might provide a cleaner separation between the Page and RootPage entities while maintaining the desired functionality.