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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:12:01+00:00 2026-06-13T12:12:01+00:00

We are getting some piece od data from the DB, but the method uses

  • 0

We are getting some piece od data from the DB, but the method uses lambda expression(or something else which i am not able to figure out!) to map it to objects and return a List of those objects rather than the DataTable.

I need assistance to understand the code, also i know what the sql is doing, i just need to understand the code after the sql which does the mapping and returns the list:

public IEnumerable<CompanyOption> GetCompanies(
    string state, string company, string lob, DateTime effectiveDate, string vehicleType)
{
    // TODO: Return type would change from IEnumerable<CompanyOptions> to IDictionary<String, IEnumerable<CompanyOptions>> 
    string sqlQuery = "SELECT [Code],[Mnemonic],[Description],[LimitCode],[LimitDescription],[LoanCode],"
                      +
                      "[LoanDescription],[EffectiveDate],[ExpirationDate],[VehicleTypeCode],[StateMinimumIndicator],"
                      + "[RecommendedLeisureIndicator],[CompanyLevelCode],[CompanyPosition]" + " FROM " + " ("
                      + "SELECT DISTINCT" + "'Code' = c.[PA_VEH_COV_CD]" + ",'Mnemonic' = cm.[SHORT_COV_DES]"
                      + ",'Description' = cm.[PVCL_VEH_COV_DES]" + ",'LeisureCode' = c.[VEH_COV_LIM_CD]"
                      + ",'LeisureDescription' = l.[Description]" + ",'LoanCode' = c.[VEH_COV_DED_CD]"
                      + ",'LoanDescription' = d.[Description]" + ",'EffectiveDate' = c.[EFFECTIVE_DT]"
                      + ",'ExpirationDate' = c.[EXPIRATION_DT]" + ",'VehicleTypeCode' = c.[PA_VEH_TYPE_CD]"
                      + ",'StateMinimumIndicator' = c.[STATE_MIN_IND]"
                      + ",'RecommendedLeisureIndicator' = c.[REC_COV_LIM_IND]"
                      + ",'CompanyLevelCode' = cm.[DSPLY_LEVEL_CD]" + ",'CompanyPosition' = cm.[COV_POS]"
                      + " FROM DB2IWS.PA_VEH_COV_LIT AS c " ////-- Company mneumonic/description
                      + " INNER JOIN DB2IWS.COV_MNEMONICS cm ON "
                      + " c.[RISK_STATE_CD] = cm.[RISK_STATE_CD] AND c.[PA_VEH_COV_CD] = cm.[PA_VEH_COV_CD]"
                      ////+ " Leisure descriptions; take 1st found from app 'SALEINET' or 'ZZZZZZZZ'"
                      ////-- TODO:  do we need to take COV_LEISURE_LIT.PA_VEH_COV_CD into account?  what is it?
                      + " LEFT OUTER JOIN ( " + " SELECT * FROM " + "(" + " SELECT [Code],[Description]"
                      + " FROM (" + " SELECT " + " [VEH_COV_LIM_CD] as [Code]"
                      ////-- overrdide description with value from legacy descr if no description
                      ////+ " ,ISNULL(NULLIF(RTRIM([PALL_LEISURE_DES]), ''), [LEGACY_LEISURE_DESC]) as [Description]"
                      + " ,[LEGACY_LEISURE_DESC] as [Description]"
                      +
                      ",ROW_NUMBER() OVER (PARTITION BY [VEH_COV_LIM_CD] ORDER BY [RISK_STATE_CD], [BUS_SRC_APP_ID]) AS RowNumber"
                      + " FROM [DB2IWS].[COV_LEISURE_LIT]" + " WHERE "
                      ////-- state from parameter of ZZ (any state)
                      + " ([RISK_STATE_CD] ='" + state + "' OR [RISK_STATE_CD] = 'ZZ') "
                      + " AND ([BUS_SRC_APP_ID] = 'SALEINET' OR [BUS_SRC_APP_ID] = 'ZZZZZZZZ') "
                      + " AND [LGG_CD2] = 'EN' " + " ) as l " + " WHERE [RowNumber] = 1 "
                      ////+" ORDER BY [Code]" cannot do order by here
                      + " )temp3 " + ") " + " AS l ON c.[VEH_COV_LIM_CD] = l.[Code] "
                      ////-- Loan descriptions; take 1st found from app 'SALEINET' or 'ZZZZZZZZ'
                      + " LEFT OUTER JOIN ( " + " SELECT * FROM " + " ( " + " SELECT [Code],[Description] "
                      + " FROM ( " + " SELECT " + " [VEH_COV_DED_CD] as [Code] "
                      /////-- overrdide description with value from legacy descr if no description
                      ////+ ",ISNULL(NULLIF(RTRIM([PADL_DED_DES]), ''), [LEGACY_DED_DESC]) as [Description] "
                      + ",[LEGACY_DED_DESC] as [Description] "
                      +
                      ",ROW_NUMBER() OVER (PARTITION BY [VEH_COV_DED_CD] ORDER BY [RISK_STATE_CD], [BUS_SRC_APP_ID]) AS RowNumber "
                      + " FROM [DB2IWS].[COV_DED_LIT]" + " WHERE " + " ([RISK_STATE_CD] ='" + state
                      + "'  OR [RISK_STATE_CD] = 'ZZ') "
                      + " AND ([BUS_SRC_APP_ID] = 'SALEINET' OR [BUS_SRC_APP_ID] = 'ZZZZZZZZ') "
                      + " AND [LGG_CD2] = 'EN' " + " ) as d " + " WHERE [RowNumber] = 1 "
                      ////+" ORDER BY [Code] "
                      + " )temp2 " + " )AS d ON c.[VEH_COV_DED_CD] = d.[Code] "
                      ////-- Exclude COV_NOT_OFFERED records
                      ////-- ??? do we also need to join VEH_COV_LIM_CD, VEH_COV_DED_CD? only if not 00000?
                      + " LEFT OUTER JOIN " + " ( " + " SELECT * " + " FROM DB2IWS.COV_NOT_OFFERED "
                      + " WHERE MASTER_COMPANY_NBR IN ('" + company + "', 'ZZ') " + " AND RISK_STATE_CD = '"
                      + state + "' " + " AND LOB_CD = '" + lob + "' " + " AND EFFECTIVE_DT <= "
                      + effectiveDate.ToShortDateString() + " " + " AND EXPIRATION_DT > "
                      + effectiveDate.ToShortDateString() + " " + " AND PA_VEH_TYPE_CD = '" + vehicleType + "' "

                      // -- this or PHY_VEH_TYPE_CD? 
                      + " ) cno ON cno.[PA_VEH_COV_CD] = cm.[PA_VEH_COV_CD] " + " WHERE "
                      + " c.[MASTER_COMPANY_NBR] = '" + company + "' " + " AND c.[RISK_STATE_CD] = '" + state
                      + "' " + " AND c.[LOB_CD] = '" + lob + "' "
                      ////+ " AND c.[EFFECTIVE_DT] <= " + effectiveDate.ToShortDateString() + " "
                      ////+ " AND c.[EXPIRATION_DT] > " + effectiveDate.ToShortDateString() + " "
                      + " AND cm.[BUS_SRC_APP_ID] = 'SALEINET' " + " AND cm.[LGG_CD2] = 'EN'"
                      ////--AND ((@MinCompanys = 0) OR 
                      ////--AND ((c.[STATE_MIN_IND] = 'Y')) 
                      ////-- Exclude COV_NOT_OFFERED records
                      + " AND cno.[PA_VEH_COV_CD] IS NULL" //// + " ORDER BY c.PA_VEH_COV_CD"
                      + " )AS temp";
    return this.Database.SqlQuery<CompanyDto>(sqlQuery).ToList().ConvertAll(
            c => new Company
                {
                    CompanyType =
                        new CompanyType
                            {
                                Code = c.Code, 
                                Mnemonic = c.Mnemonic, 
                                Description = c.Description, 
                                CompanyLevel = c.CompanyLevelCode, 
                                CompanyPosition = Convert.ToInt32(c.CompanyPosition)
                            }, 
                    Leisure =
                        new Leisure
                            {
                                Code = c.LeisureCode, 
                                Description = c.LeisureDescription, 
                                Minimum = "Y".Equals(c.StateMinimumIndicator, StringComparison.OrdinalIgnoreCase), 
                                Recommended =
                                    "Y".Equals(c.RecommendedLeisureIndicator, StringComparison.OrdinalIgnoreCase)
                            }, 
                    Loan =
                        new Loan { Code = c.LoanCode, Description = c.LoanDescription }
                }).ToLookup(
            c =>
            new Tuple<string, string, string, string, int>(
                c.CompanyType.Code, 
                c.CompanyType.Mnemonic, 
                c.CompanyType.Description, 
                c.CompanyType.CompanyLevel, 
                c.CompanyType.CompanyPosition)).Select(
                    t =>
                    new CompanyOption
                        {
                            CompanyType =
                                new CompanyType
                                    {
                                        Code = t.Key.Item1, 
                                        Mnemonic = t.Key.Item2, 
                                        Description = t.Key.Item3, 
                                        CompanyLevel = t.Key.Item4, 
                                        CompanyPosition = t.Key.Item5
                                    }, 
                            Leisures =
                                (from Company c in t select c.Leisure).GroupBy(l => l.Code).Select(
                                    gr => gr.First()), 
                            Loans =
                                (from Company c in t select c.Loan).GroupBy(d => d.Code).Select(
                                    gr => gr.First())
                        }).OrderBy(t => t.CompanyType.CompanyPosition);
}
  • 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-13T12:12:02+00:00Added an answer on June 13, 2026 at 12:12 pm
    return this.Database
        .SqlQuery<CompanyDto>(sqlQuery).ToList()
    
        // ConvertAll -> Converts every element in the list to the specified type.
        .ConvertAll(
            c => new Company {
                CompanyType =
                    new CompanyType
                        {
                            Code = c.Code, 
                            Mnemonic = c.Mnemonic, 
                            Description = c.Description, 
                            CompanyLevel = c.CompanyLevelCode, 
                            CompanyPosition = Convert.ToInt32(c.CompanyPosition)
                        }, 
                Leisure =
                    new Leisure
                        {
                            Code = c.LeisureCode, 
                            Description = c.LeisureDescription, 
                            Minimum = "Y".Equals(c.StateMinimumIndicator, StringComparison.OrdinalIgnoreCase), 
                            Recommended =
                                "Y".Equals(c.RecommendedLeisureIndicator, StringComparison.OrdinalIgnoreCase)
                        }, 
                Loan =
                    new Loan { Code = c.LoanCode, Description = c.LoanDescription }
            }
        )
    
        // Convert to lookup list, in other words, add a key.
        .ToLookup(
            c =>
                new Tuple<string, string, string, string, int>(
                    c.CompanyType.Code, 
                    c.CompanyType.Mnemonic, 
                    c.CompanyType.Description, 
                    c.CompanyType.CompanyLevel, 
                    c.CompanyType.CompanyPosition
                )
        )
    
        // And convert again to another type
        .Select(
                t =>
                new CompanyOption
                    {
                        CompanyType =
                            new CompanyType
                                {
                                    Code = t.Key.Item1, 
                                    Mnemonic = t.Key.Item2, 
                                    Description = t.Key.Item3, 
                                    CompanyLevel = t.Key.Item4, 
                                    CompanyPosition = t.Key.Item5
                                }, 
                        Leisures =
                            (from Company c in t select c.Leisure).GroupBy(l => l.Code).Select(
                                gr => gr.First()), 
                        Loans =
                            (from Company c in t select c.Loan).GroupBy(d => d.Code).Select(
                                gr => gr.First())
                    }).OrderBy(t => t.CompanyType.CompanyPosition);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a piece of code which combines an in-memory list with some data
I have following piece of code which posts some data into database: $post =
One of my database fields in a table is getting modified by some piece
after some advice regarding a problem i am getting using a linux based piece
I'm getting some inexplicable behavior from easymock and a JUnit test case. I'm receiving
I've got some weird images I'm getting from some hardware at work. They're from
I am having some trouble getting a test to run that uses TestNg's @DataProvider
I'm trying to extract some textual data from a PDF file. To do this,
i am trying to pass some data from my notification intent to one of
I need to build an application which can receive data from over a network

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.