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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:29:39+00:00 2026-05-27T08:29:39+00:00

I have this class… public class MyDTO { public int Id { get; set;

  • 0

I have this class…

public class MyDTO
{
    public int Id { get; set; }

    public bool Selected { get; set; }
}

and then use dapper to attempt to create a list like this…

            var list = this.db.OpenConnection().Query<MyDTO>(
            @"SELECT T1.id, T2.id IS NOT NULL AS selected
            FROM     table1 T1
            LEFT
            JOIN     table2 T2 
            ON   T2.id = T1.id
            AND  Tl.id = @Id",
            new { Id = id });

which returns a result set like this….

id  selected
 9         0
10         1
11         1
12         0

But when code above is executed, i get an error

[InvalidCastException: Specified cast is not valid.]
Deserialize3d3c9260-abcb-4964-97c1-4a4e66b786d3(IDataReader ) +354

[DataException: Error parsing column 2 (selected=0 - Int64)]
Dapper.SqlMapper.ThrowDataException(Exception ex, Int32 index, IDataReader reader) in     C:\Projects\Web\SqlMapper.cs:1685
Deserialize3d3c9260-abcb-4964-97c1-4a4e66b786d3(IDataReader ) +432
Dapper.<QueryInternal>d__13`1.MoveNext() in C:\Projects\Web\Source\SqlMapper.cs:608
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +327
System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
Dapper.SqlMapper.Query(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in C:\Projects\Web\Source\SqlMapper.cs:538

I’m going to create a “Translating” property for now, but is this an unusual use case?

  • 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-27T08:29:39+00:00Added an answer on May 27, 2026 at 8:29 am

    I’m not sure if this is the best way to do it, but it should do the trick:

    SELECT T1.id, CAST(CASE WHEN T2.id IS NULL THEN 0 ELSE 1 END AS BIT) AS selected
    FROM ...
    

    (To be honest, I’m not convinced that your T2.id IS NOT NULL AS selected clause is legal T-SQL in the first place, but if you say that it’s working then I’ll take your word for it!)

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

Sidebar

Related Questions

I have this class. public class Foo { public Guid Id { get; set;
I have this class: public class MyEntity { public virtual int Id { get;
I have this class: public class TextFiller { public HtmlText Text { get; set;
I have this class and table: public class Foo { public Guid Id {get;set;}
I have this class called Table: class Table { public string Name { get
I have this class public class Subject { int ID; string Name; int Semester;
i have this : class A { public : A(int i ) : m_S(i)
I have this class/interface definitions in C# public class FooBase { ... protected bool
I have this class class Point2D { public: bool isValid(); // ... private: double
I have this class... public class StartStopTouple { public int iStart; public int iStop;

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.