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

I’m working on a database and LINQ to SQL ASP.NET web app. My setup includes two types of pages: regular and root. I’ve got tables for Page and RootPage:

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

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

I’m thinking about setting the IsDiscriminator property for the IsRoot column in my DBML file. This should make the RootPage class inherit from Page, right?

I want to use code like this:

var db = new MyDataContext();
var rootPages = db.Pages.OfType<RootPage>();

// Or

var newRoot = new RootPage {
    HtmlTitle = "Home",
    FavIcon = "icon.png"
};
db.Pages.Add(newRoot);
db.SubmitChanges();

My main question is: can the IsDiscriminator column be nullable or false in LINQ to SQL? Will this setup work as I expect? I’m not sure about the inheritance behavior here.

hm, interesting question! have u considered using an abstract base class for Page instead? that might give u more flexibility. what if u need more page types in the future? how do u handle url routing for different page types? curious to hear ur thoughts on this approach!

In LINQ to SQL, the discriminator column plays a crucial role in mapping inheritance. For the scenario you described, the IsRoot column must indeed be non-nullable. Setting it to true for RootPage entries and false for regular Page entries allows LINQ to SQL to effectively distinguish and map the relationships between your classes. This method of using the IsDiscriminator property ensures that queries such as OfType() function correctly, though it is important to thoroughly test your setup to confirm that it meets all of your specific requirements and querying needs.

hey whisperingwind, i’ve faced this issue. the discriminator must have a non-null bool value, so isroot must be true for rootpages and false otherwise. get this set up properly and inheritance works as expected. hope it helps!