Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 130705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:59:24+00:00 2026-05-11T05:59:24+00:00

I am writing an application where we will need to extend a basic entity

  • 0

I am writing an application where we will need to extend a basic entity into a number of different things (eg employee, vehicle etc). The design is as such that there is a Entity table and a second table with type specific values eg an employee will have an ID Number but a vehicle will have a registration number.

I have inherited from the class entity generated in the Data Context but am having trouble with the casting in my repository. What is the correct way of doing this?

public class cAccountEmployee : cAccountEntity {     public string id_number     {         get         {             try             {                 return this.cAccountEntityValues.Single(e => e.type == 1).value;             }             catch (Exception)             {                 return '';             }         }          set         {             try             {                 this.cAccountEntityValues.Single(e => e.type == 1).value = value;             }             catch (Exception)             {                 this.cAccountEntityValues.Add(new cAccountEntityValue()                                             {                                                 accountentity_id = this.id,                                                 cAccountEntity = this,                                                 type = 1,                                                 value = value                                             });             }         }     } 

}

Then in my repository (does not inherit anything)

public IEnumerable<cAccountEmployee> All(int accountholder_id)     {         return db.cAccountEntities.Where(e => e.accountholder_id == accountholder_id).OrderBy(a => a.name).Cast<cAccountEmployee>();     }      public cAccountEmployee Single(int id)     {         return db.cAccountEntities.Single(a => a.id == id) as cAccountEmployee;     } 

The cast fails in the single method and hence I get back null. It is my understanding you cannot define explicit or implicit operators from or to a base class? How can I get the base class Linq result to cast up to the inherited Employee class, while still maintaining its db state so I can submit changes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:59:25+00:00Added an answer on May 11, 2026 at 5:59 am

    With LINQ-to-SQL, there are two ways inheritance can work:

    • discriminator over a single table (not suitable since your data is not homogeneous)
    • base-class / multi-table (not that this isn’t supported in the dbml – only if you write the classes manually)

    LINQ-to-SQL does not support multi-table inheritance (i.e. a single object with data from multiple tables). Entity Framework does, but is more complex; you use .Cast<T> and .OfType<T> in EF to cast/filter based on sub-types.

    You might want to look at:

    • querying based on an ID (combine with GetTable<T>())
    • specifying a base-class in the dbml

    What is the purpose of the base class here? If it adds behaviour, then you can edit the dbml to specify a common base-class for all your entities. If it has data properties then it gets trickier.

    Personally, I simply wouldn’t do it this way… I would keep separate classes for the different types, and use the data-context correctly, using the separate tables per type:

    public IEnumerable<Employee> All(int accountholder_id) {     return db.Employees.Where(e => e.accountholder_id == accountholder_id)         .OrderBy(a => a.name); }  public Employee Single(int id) {     return db.Employees.Single(a => a.id == id); } 

    So – can you clarify what the cAccountEntity does here?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 114k
  • Answers 114k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use this: <title> <asp:ContentPlaceHolder ID="titleContent" runat="server" /> <%= "- My… May 11, 2026 at 10:14 pm
  • Editorial Team
    Editorial Team added an answer If you can install a NTP (Network Time Protocol) server… May 11, 2026 at 10:14 pm
  • Editorial Team
    Editorial Team added an answer Question 1 The ?? is called the null-coalescing operator, and… May 11, 2026 at 10:14 pm

Related Questions

I am writing an app which - similarly to many apps out there -
I'm writing (in C# with .NET 3.5) an administrative application which will poll multiple
At the company I work for, I have created a Error Logging class to
Background In a C# command-line app I'm writing, several of the parameters have yes

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.