Skip to content

Instantly share code, notes, and snippets.

@dandohotaru
Created February 10, 2018 18:08
Show Gist options
  • Save dandohotaru/0209e434686093ed8d7e8f2a8b0ea120 to your computer and use it in GitHub Desktop.
Save dandohotaru/0209e434686093ed8d7e8f2a8b0ea120 to your computer and use it in GitHub Desktop.
//Product ##
//ProductId
//ProductName
//IsDeleted(bit)
//
//ProductTag
//ProductTagId
//ProductId
//TagName
//IsDeleted(bit)
//
//ProductCategory
//ProductCategoryId
//ProductId
//CategoryName
//IsDeleted(bit)
void Main()
{
var context = new Context();
var query = from product in context.Products
let tags = from tag in context.Tags
where tag.IsDeleted
&& tag.ProductId == product.ProductId
select tag.TagName
let categories = from category in context.Categories
where category.IsDeleted
&& category.ProductId == product.ProductId
select category.CategoryName
where !product.IsDeleted
select new
{
Id = product.ProductId,
Name = product.ProductName,
Tags = string.Join(", ", tags)
Categories = string.Join(" ", categories)
};
}
class Context
{
public IEnumerable<Product> Products { get; set; }
public IEnumerable<ProductTag> Tags { get; set; }
public IEnumerable<ProductCategory> Categories { get; set; }
}
class Product
{
public int ProductId { get; set; }
public string ProductName { get; set; }
public bool IsDeleted { get; set; }
}
class ProductTag
{
public int ProductId { get; set; }
public int ProductTagId { get; set; }
public string TagName { get; set; }
public bool IsDeleted { get; set; }
}
class ProductCategory
{
public int ProductCategoryId { get; set; }
public int ProductId { get; set; }
public string CategoryName { get; set; }
public bool IsDeleted { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment