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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:20:28+00:00 2026-05-16T05:20:28+00:00

i want to use generic class to shorter my codes because 1) GetMaintData(int taskID)

  • 0

i want to use generic class to shorter my codes because

1) GetMaintData(int taskID) RelTypeId and RefMaintenance
2) GetAliSpReqs(int taskID) RelTypeId and RefAliSpReq

if you look below method you can see only TypeId and Ref data. i think that i can write new clear codes via generic class like that:

http://www.thereforesystems.com/dynamic-sort-with-linq/

  public void GetData<TKey>(List<TaskRelation> cities, Func<TaskRelation, TKey> selector)
        {
//include all GetMaintData,GetAliSpReqs,GetZone,GetAccess
        }
  public  class EngGetCalculatedTaskField
    {
        private static TaskMaintenanceDataDataContext engTaskCtx { get; set; }

        public EngGetCalculatedTaskField()
        {
            engTaskCtx = new TaskMaintenanceDataDataContext();
        }
        public   string GetMaintData(int taskID)
        {
               var query = engTaskCtx.TaskRelations.Where(r => r.TaskId == taskID &&
                    r.RelTypeId == 12).Select(r => r.RefMaintenance.shortdesc);
                return string.Join("; ", query.ToArray());
        }
        public  string GetAliSpReqs(int taskID)
        {
             var query = engTaskCtx.TaskRelations.Where(r => r.TaskId == taskID
                                           && r.RelTypeId == 13)
                               .Select(r => r.RefAliSpReq.shortdesc);
                return string.Join("; ", query.ToArray());
        }
        public  string GetAccess(int taskID)
        {
             var query = engTaskCtx.TaskRelations.Where(r => r.TaskId == taskID
                                     && r.RelTypeId == 15)
                         .Select(r => r.RefAccessPanel.shortdesc);
             return string.Join("; ", query.ToArray());
        }
        public  string GetZone(int taskID)
        {
            var query = engTaskCtx.TaskRelations.Where(r => r.TaskId == taskID
                                    && r.RelTypeId == 14)
                        .Select(r => r.RefZone.shortdesc);
            return string.Join("; ", query.ToArray());
        }
  • 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-16T05:20:29+00:00Added an answer on May 16, 2026 at 5:20 am

    Something like this:

    public string GetList(IEnumerable<TaskRelation> relations,
                          int taskId, int relTypeId,
                          Func<TaskRelation, string> projection)
    {
        var query = relations.Where(r => r.TaskId == taskId && 
                                         r.RelTypeID == relTypeId)
                             .Select(projection));
                             .ToArray()
        return string.Join("; ", query.ToArray());
    }
    

    Then use it like this:

    string zones = GetList(reslations, taskID, 14, r => r.RefZone.shortdesc);
    

    Note that I’ve assumed LINQ to Objects – if this is LINQ to SQL (or something similar) then you should specify IQueryable<TaskRelation> and Expression<Func<TaskRelation, string>> so that the filtering and projecting can be done at the data source.

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

Sidebar

Related Questions

I want to use the DbProvider class to construct a generic DAL component. This
I am working on a generic class and I want to use Class.cast() to
I want to use a generic class inside a nested static interface. My objective
I have a generic Repository<T> class I want to use with an ObjectDataSource. Repository<T>
I want use BYTE_ORDER macro in my Xcode project but i can't because i
I want to get use of dictionary items like I do in List generic
I want to create a generic class, whose builder would not return an instance
I want to use the class information that was captured by the setup of
In my class, I want to use a dictionary with the following declaration: Dictionary<string,
As you know there is a generic class List in .NET framework. I want

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.