Created
February 10, 2018 18:08
-
-
Save dandohotaru/0209e434686093ed8d7e8f2a8b0ea120 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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