C# eaver不知道这些技术被称为什么,我只是更喜欢在子实体上迭代1000次时生成一个SQL server请求的方法,而不是1000个请求。您好,您知道这一点吗?我没有,我也从未再次讨论过这个问题。这应该被删除,因为这不是一个答案,而是一个问题。 //
C# eaver不知道这些技术被称为什么,我只是更喜欢在子实体上迭代1000次时生成一个SQL server请求的方法,而不是1000个请求。您好,您知道这一点吗?我没有,我也从未再次讨论过这个问题。这应该被删除,因为这不是一个答案,而是一个问题。 //,c#,asp.net,linq-to-sql,C#,Asp.net,Linq To Sql,eaver不知道这些技术被称为什么,我只是更喜欢在子实体上迭代1000次时生成一个SQL server请求的方法,而不是1000个请求。您好,您知道这一点吗?我没有,我也从未再次讨论过这个问题。这应该被删除,因为这不是一个答案,而是一个问题。 //cdc is my datacontext DataLoadOptions options = new DataLoadOptions(); options.LoadWith<Global>(p => p.Category
eaver不知道这些技术被称为什么,我只是更喜欢在子实体上迭代1000次时生成一个SQL server请求的方法,而不是1000个请求。您好,您知道这一点吗?我没有,我也从未再次讨论过这个问题。这应该被删除,因为这不是一个答案,而是一个问题。
//cdc is my datacontext
DataLoadOptions options = new DataLoadOptions();
options.LoadWith<Global>(p => p.Category);
options.AssociateWith<Global>(p => p.Category.OrderBy(o => o.SortOrder));
options.LoadWith<Category>(p => p.ItemTypes);
options.AssociateWith<Category>(p => p.ItemTypes.OrderBy(o => o.SortOrder));
cdc.LoadOptions = options;
TraceTextWriter traceWriter = new TraceTextWriter();
cdc.Log = traceWriter;
var query =
from g in cdc.Global
where g.active == true && g.globalid == 41
select g;
var globalList = query.ToList();
// In this case I have hardcoded an id while I figure this out
// but intend on trying to figure out a way to include something like globalid in (#,#,#)
foreach (var g in globalList)
{
// I only have one result set, but if I had multiple globals this would run however many times and execute multiple queries like it does farther down in the hierarchy
List<Category> categoryList = g.category.ToList<Category>();
// Doing some processing that sticks parent record into a hierarchical collection
var categories = (from comp in categoryList
where comp.Type == i
select comp).ToList<Category>();
foreach (var c in categories)
{
// Doing some processing that stick child records into a hierarchical collection
// Here is where multiple queries are run for each type collection in the category
// I want to somehow run this above the loop once where I can get all the Items for the categories
// And just do a filter
List<ItemType> typeList = c.ItemTypes.ToList<ItemType>();
var itemTypes = (from cat in TypeList
where cat.itemLevel == 2
select cat).ToList<ItemType>();
foreach (var t in itemTypes)
{
// Doing some processing that stick child records into a hierarchical collection
}
}
}
var query =
from g in cdc.Global
where g.active == true && g.globalId == 41
select g;
var globalList = query.ToList();
List<Category> categoryList = g.category.ToList<Category>();
var categoryIds = from c in cdc.Category
where c.globalId == g.globalId
select c.categoryId;
var types = from t in cdc.ItemTypes
where categoryIds.Any(i => i == t.categoryId)
select t;
List<ItemType> TypeList = types.ToList<ItemType>();
var items = from i in cdc.Items
from d in cdc.ItemData
where i.ItemId == d.ItemId && d.labelId == 1
where types.Any(i => i == r.ItemTypes)
select new
{
i.Id,
// A Bunch of more fields shortened for berevity
d.Data
};
var ItemList = items.ToList();
// Keep on going down the hierarchy if you need more child results
// Do your processing psuedocode
for each item in list
filter child list
for each item in child list
.....
//