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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:20:08+00:00 2026-05-22T14:20:08+00:00

var sql = @SELECT a.id AS `Id`, a.thing AS `Name`, b.id AS `CategoryId`, b.something

  • 0
var sql = @"SELECT
    a.id AS `Id`, 
    a.thing AS `Name`, 
    b.id AS `CategoryId`,
    b.something AS `CategoryName`  
FROM ..";

var products = connection.Query<Product, Category, Product>(sql,
    (product, category) =>
    {
        product.Category = category;
        return product;
    }, 
    splitOn: "CategoryId");

foreach(var p in products)
{
    System.Diagnostics.Debug.WriteLine("{0} (#{1}) in {2} (#{3})", p.Name, p.Id, p.Category.Name, p.Category.Id);
}

Results in:

'First (#1) in  (#0)'
'Second (#2) in  (#0)'

CategoryId and CategoryName has values since the following

var products = connection.Query(sql).Select<dynamic, Product>(x => new Product
{
    Id = x.Id,
    Name = x.Name,
    Category = new Category { Id = x.CategoryId, Name = x.CategoryName }
});

Results in:

'First (#1) in My Category (#10)'
'Second (#2) in My Category (#10)'

I’m connecting to a MySQL database if that has anything to do with it.

  • 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-22T14:20:09+00:00Added an answer on May 22, 2026 at 2:20 pm

    The simplest way is to call them all Id (case-insensitive, so just a.id and b.id are fine); then you can use:

        public void TestMultiMapWithSplit()
        {
            var sql = @"select 1 as Id, 'abc' as Name, 2 as Id, 'def' as Name";
            var product = connection.Query<Product, Category, Product>(sql,
               (prod, cat) =>
               {
                   prod.Category = cat;
                   return prod;
               }).First();
            // assertions
            product.Id.IsEqualTo(1);
            product.Name.IsEqualTo("abc");
            product.Category.Id.IsEqualTo(2);
            product.Category.Name.IsEqualTo("def");
        }
    

    If you can’t do that, there is an optional splitOn (string) parameter that takes a comma-separated list of columns to treat at splits.

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

Sidebar

Related Questions

I am using the following query in entity sql Select n.Name as NodeNameN from
The following SQL SELECT * FROM customers converted to this in LINQ var customers
My code for sql connection using linq is: var query1 = from u in
I need to get the table name to query from a table. var tableName
I have the following SQL query: SELECT Comment, JD, Jurisdiction, RegStatus, Region, SPDR_NAME FROM
Code: var result = db.rows.Take(30).ToList().Select(a => AMethod(a)); db.rows.Take(30) is Linq-To-SQL I am using ToList()
how can the ThenBy be translated to Linq-To-Sql , please? var movies = _db.Movies.Orderby(c
Here's what I've got so far- $awards_sql_1 = mysql_query('SELECT * FROM categories WHERE section_id
Here is what i have: a SQL CE database, that holds this Category table,
I need to create an SQL query to insert some data into a table

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.