本文整理汇总了C#中BlogMLBlog.Where方法的典型用法代码示例。如果您正苦于以下问题:C# BlogMLBlog.Where方法的具体用法?C# BlogMLBlog.Where怎么用?C# BlogMLBlog.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlogMLBlog
的用法示例。
在下文中一共展示了BlogMLBlog.Where方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportCategories
private IDictionary<string, Guid> ImportCategories(BlogMLBlog.CategoryCollection categories,
IEnumerable<BlogMLPost> blogs,
ref List<CategoryTree> newCategoriesTreeList,
ref List<Category> newCategoriesList,
bool ReuseExistingCategories,
bool RecreateCategoryTree)
{
var dictionary = new Dictionary<string, Guid>();
if (categories.Count == 0)
{
// old export method when only categories ids are exported
var oldExistingCategoriesIds = new List<Guid>();
blogs.Select(t => t.Categories).ForEach(
t =>
{
for (int i = 0; i < t.Count; i++)
{
Guid parsedGuid;
if (Guid.TryParse(t[i].Ref, out parsedGuid) && !oldExistingCategoriesIds.Contains(parsedGuid))
{
oldExistingCategoriesIds.Add(parsedGuid);
}
}
});
oldExistingCategoriesIds = repository.AsQueryable<Category>().Where(t => oldExistingCategoriesIds.Contains(t.Id)).Select(t => t.Id).ToList();
oldExistingCategoriesIds.ForEach(t => dictionary.Add(t.ToString(), t));
return dictionary;
}
if (RecreateCategoryTree)
{
// sort categories that parents would be first
for (int i = 0; i < categories.Count; i++)
{
for (int j = 0; j < categories.Count; j++)
{
if (categories[i].ID == categories[j].ParentRef && i > j)
{
var tmp = categories[j];
categories[j] = categories[i];
categories[i] = tmp;
}
}
}
var newIdsForCategories = new Dictionary<string, Guid>();
// regenerate new ids for category tree
foreach (var category in categories)
{
if (!newIdsForCategories.ContainsKey(category.ID))
{
newIdsForCategories.Add(category.ID, Guid.NewGuid());
}
if (!string.IsNullOrEmpty(category.ParentRef) && !newIdsForCategories.ContainsKey(category.ParentRef))
{
newIdsForCategories.Add(category.ParentRef, Guid.NewGuid());
}
}
foreach (var category in categories)
{
category.ID = newIdsForCategories[category.ID].ToString();
if (!string.IsNullOrEmpty(category.ParentRef))
{
category.ParentRef = newIdsForCategories[category.ParentRef].ToString();
}
}
var refrencedCategoriesIds = new List<Guid>();
foreach (var blog in blogs)
{
for (int i = 0; i < blog.Categories.Count; i++)
{
var category = blog.Categories[i];
// it may be that category is deleted but it is still linked to blog and that link is not deleted
if (newIdsForCategories.ContainsKey(category.Ref))
{
var newCategoryId = newIdsForCategories[category.Ref];
category.Ref = newCategoryId.ToString();
refrencedCategoriesIds.Add(newCategoryId);
}
}
}
Guid testParseGuid;
var oldIdsCategories = newIdsForCategories.Keys.Where(t => Guid.TryParse(t, out testParseGuid)).Select(t => new Guid(t)).ToList();
var existingCategoriesIdsFuture = repository.AsQueryable<Category>().Select(t => t.Id).Where(t => oldIdsCategories.Contains(t)).ToFuture();
var availableFor = repository.AsQueryable<CategorizableItem>().ToFuture().ToList();
var existingCategoriesIds = existingCategoriesIdsFuture.ToList();
// creates categories trees
foreach (var categoryTree in categories.Where(c => string.IsNullOrEmpty(c.ParentRef)))
{
var newTree = new CategoryTree
{
Title = categoryTree.Title,
CreatedOn = categoryTree.DateCreated,
ModifiedOn = categoryTree.DateModified,
Id = new Guid(categoryTree.ID)
};
newTree.AvailableFor = new List<CategoryTreeCategorizableItem>();
foreach (var categorizableItem in availableFor)
//.........这里部分代码省略.........