Select specific fields of mapped object

Open
#660 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
csharp
Domain
database

Research direction

Start at the connection.Query calls shown in cases 1–3 and compare them with CreateTable. Check whether selecting Text, Id, or Id and Real can be mapped and serialized into string, int, or MySubObject. Done means documenting the supported approach or clearly recording that partial mapped-object selection is unsupported.

Written by the indexing model from the issue text.

Description

Question:
Is it currently possible to select only specific fields (1, many) of the mapped object and get them serialized? I can't find any documentation or examples of this.

Example:

Database structure:

CREATE TABLE MyObjects (
    Id INTEGER PRIMARY KEY,
    Text TEXT,
    Real REAL,
);

Code structure:

interface IMySubObject
{
    int Id {get; }
    double Real {get; }
}

class MyObject : IMySubObject
{
    [PrimaryKey, AutoIncremented]
    public int Id {get; set;}
    public string Text {get; set;}
    public double Real {get; set;}
}

class MySubObject : IMySubObject
{
    public int Id {get; set;}
    public double Real {get; set;}
}

Setup:

connection.CreateTable<MyObject >();

Queries:

case 1:
var query = "SELECT Text FROM MyObjects WHERE Id = 10";
connection.Query<string>(query);

case 2:
var query = "SELECT Id FROM MyObjects WHERE Text LIKE '%text%'";
connection.Query<int>(query,);

case 3:
var query = "SELECT Id, Real FROM MyObjects WHERE Text LIKE '%text%'";
connection.Query<MySubObject >(query,);
Dominant language
C#
Stars
4.5k
Forks
1.4k
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from praeclarum/sqlite-net

All issues in praeclarum/sqlite-net

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.