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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:59:03+00:00 2026-05-18T23:59:03+00:00

I have an implementation like that: public interface IGenericRepository { //… void Update<T>(T entity,

  • 0

I have an implementation like that:

 public interface IGenericRepository
 {
    //...
    void Update<T>(T entity, string keyPropertyName = "Id") where T : class;
    void Delete<T>(T entity, string keyPropertyName = "Id") where T : class;
    //...
}

public abstract class GenericRepositoryBase : IGenericRepository
{
    //...
    void Update<T>(T entity, string keyPropertyName = "Id") where T : class;
    void Delete<T>(T entity, string keyPropertyName = "Id") where T : class;
    //..
}

public class GenericRepository : GenericRepositoryBase
{
    //..
    public override void Update<T>(T entity, string keyPropertyName = "Id")
    {
       //..
    }

    public override void Delete<T>(T entity, string keyPropertyName = "Id")
    {
        //..
    }
    //..
}

Each time i am specifying(hard coding) keyPropertyName = “Id” it is looking not good.

May be some one has an idea how i may declare value const string defaultKeyPropertyName = "Id" just in one place and then everywhere just use like that.

//...
void Update<T>(T entity, string keyPropertyName = defaultKeyPropertyName) where T : class;
void Delete<T>(T entity, string keyPropertyName = defaultKeyPropertyName) where T : class;
//..

or it can be done somehow else?

any ideas?

  • 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-18T23:59:04+00:00Added an answer on May 18, 2026 at 11:59 pm

    You can use a const if you want, and make a class that holds it. C# has no concept of a global variable, so this is as close as it will get:

    public static class Defaults
    {
        public const string KeyName = "Id";        
    }
    
    public abstract class GenericRepositoryBase
    {
        //...
        protected abstract void Update<T>(T entity, string keyPropertyName = Defaults.KeyName) where T : class;
        protected abstract void Delete<T>(T entity, string keyPropertyName = Defaults.KeyName) where T : class;
        //..
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have coded a service like that : public interface IMyInterface { ... }
I have code that looks like follows: public interface BaseDAO{ // marker interface }
I have an interface like this: public interface DataObject { ... public void copyFrom(DataObject
Suppose you have an interface like this: public interface IDoSomething<out T> { T DoSomething(object
I have an interface -- EventHandler -- that declares several methods. public interface EventHandler
I have a priority queue implementation in C# that I want to add a
I have heard that the Java implementation of Generics is not as good as
If I have a service definition/implementation like this: using System; using System.ServiceModel; namespace aspace.service
I have a typed message broker similar to what Caliburn provides: public interface IMessageBroker
I have the following generic question Here is a my generic message interface. public

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.