Skip to content

queries select projections

Todd Thomson edited this page Sep 7, 2018 · 3 revisions

Data Projections

Entities.Sqlite supports select projections to Data Transfer Objects (DTOs).

Select Projection to DTO

public class ProductDto
{
    public string ProductDescription { get; set; }
}
var q = from p in context.Products
        select new ProductDto
        {
            ProductDescription = p.Name
        };

var result = q.ToList();

Select Projection to DTO Using Join

public class JoinedProductSuppliers
{
    public Product Product { get; set; }
    public Supplier Supplier { get; set; }
}
var q = from p in context.Products
             join s in context.Suppliers on p.Id equals s.Id
             select new JoinedProductSuppliers
             {
                 Product = p,
                 Supplier = s
              };

var result = q.ToList();
Clone this wiki locally