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 8265107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:41:05+00:00 2026-06-08T04:41:05+00:00

I am trying to create a generic class: public class ClassName<T> { public T

  • 0

I am trying to create a generic class:

public class ClassName<T>
{
    public T AccessEntity(string id)
    {
        return (from e in ServiceContext.CreateQuery<T>(TableName)
                where e.RowKey == id // error here!
                select e).FirstOrDefault();
    }
}

In this code I am getting error that:

T does not contain the definition for RowKey

but the parameters which will replace the T at runtime have the definition of RowKey. Maybe because complier is not getting the definition for RowKey in T at compile time, that`s why I am getting this error. Can anybody tell me how to solve this issue?

  • 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-06-08T04:41:06+00:00Added an answer on June 8, 2026 at 4:41 am

    To do that you would need an interface constraint:

    interface IHazRowKey {
         string RowKey { get; } 
    }
    

    And specify this restriction:

    public class classname<T> where T : IHazRowKey {...}
    

    And specify : IHazRowKey on each of the implementations:

    public class Foo : IHazRowKey {....}
    

    The existing RowKey member should match it (assuming it is a property, not a field), so you shouldn’t need to add any other extra code. If it is actually a field (which it shouldn’t be, IMO) then:

    public class Foo : IHazRowKey {
        string HazRowKey.RowKey { get { return this.RowKey; } }
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a generic class to write and read Objects to/from
I'm trying to create a UserControl that inherits from a generic class. It does
I'm trying to create a generic class in PHP that will provide a way
I am trying to create a generic class which new's up an instance of
I'm trying to create an instance of a generic class using a Type object.
I am trying to create a class implementing the generic IComparer of my own
I am trying to create a generic typed class, but am running into a
I am trying to create a JSONMessage class that can parse a json string
I'm trying to create my own class template for Visual Studio called Public Class.
I'm trying to create a generic Controller Class for generic events. But these these

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.