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

  • Home
  • SEARCH
  • 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 6176265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:04:12+00:00 2026-05-24T00:04:12+00:00

I have a generic class that essentially extends a linq class. This means that

  • 0

I have a generic class that essentially extends a linq class. This means that I can’t just extend the linq class, I need to have a separate generic class.

public LinqCake // Linq Class from DBML
{
     string Name;
     FrostingType Type;
}

public class Cake<T> : LinqCake where T is FrostingType
{
   public bool SomeProperty 
   {
          get 
          {
             return LinqCake.Type == FrostingType;
          }
   }          

   // I basically want to do something like this,
   // but I obviously can't because this code isn't valid
   public Cake (int ID)
   {
           this = db.LinqCakes.Where(x=>x.ID = ID).Single();
   }
}

public void Main()
{
   Cake<Chocolate> ChocolateCake = Cake<Chocolate>(7);
   Console.WriteLine(ChocolateCake.SomeProperty);
}

I basically want to populate Cake’s inherited class LinqCake with information from the database. Can I do this with just an implicit cast?

How do I accomplish the spirit of what I’m trying to do? I can think of two ways of sort of doing this; A) Add a private LinqCake member B) Essentially just read in each property of the LinqCake class into duplicate properties of the Cake class.

I feel like there is a better solution, any idea?

  • 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. Editorial Team
    Editorial Team
    2026-05-24T00:04:12+00:00Added an answer on May 24, 2026 at 12:04 am

    If I understand your question your doing a projection here which involves mapping the fields from type LinqCake to those of type Cake. You can’t set a LinqCake to be a Cake because it isn’t specified like that in your type hierarchy.

    Maybe a tool like AutoMapper can help you.

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

Sidebar

Related Questions

Imagine that I have a generic base class like this: public abstract class AnimalDTO<TA,
I have a generic class that takes a type T . Within this class
I have a generic class public MyClass<TContext, T> where TContext : DataContext that effectively
I have a class that inherits a generic dictionary and an inteface public class
I have generic type that looks like: public class GenericClass<T, U> where T :
I have a generic class that implements IList public class ListBase<T>: IList<T>, IListBase{ IEnumerator<T>
This is best explained using code. I have a generic class that has a
I have a generic class that should allow any type, primitive or otherwise. The
I have a generic class that I'm trying to implement implicit type casting for.
I have a generic class that needs to limit an enum depending on the

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.