Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output data not automatically mapping non-specified fields #1

Open
adamzuckerman opened this issue Apr 28, 2016 · 0 comments
Open

Output data not automatically mapping non-specified fields #1

adamzuckerman opened this issue Apr 28, 2016 · 0 comments

Comments

@adamzuckerman
Copy link

adamzuckerman commented Apr 28, 2016

I have a model class:

public class QueryResults
{
  public double Distance { get; set; }
  public string StreetLine1 { get; set; }
  public string StreetLine2 { get; set; }
  public string City { get; set; }
  public string State { get; set; }
}

In my data access layer, one of the methods maps some of the model's fields.

var mappings = new ColumnMappingCollection();

// Start defining the mappings between each property/column for a type
mappings.RegisterType<QueryResults>()
  .MapProperty(x => x.Distance).ToColumn("distance")
  .MapProperty(x => x.StreetLine1).ToColumn("street1")
  .MapProperty(x => x.StreetLine2).ToColumn("street2");

mappings.RegisterWithDapper();

string query = "SELECT distance, " +
  "sites.street1, " +
  "sites.street2,  " +
  "sites.city, " +
  "sites.state, " +
  "FROM mytable ";

// Execute my query using Dapper 
IEnumerable<QueryResults> results = connection.Query<QueryResults>(query);

The results returned by the query do not include the unmapped properties/fields. Specifically, the City and State fields do not get populated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant