Лучший титул, который я мог придумать, однако, немного более сложный.
// Hit the database once and get all the categories;
IQueryable<Category> qryCategoryList = _repository.Select<Category>();
// get initial parents
var parentCategories = qryCategoryList.Where(x => x.ParentCategoryId == null);
foreach (Category parentCategory in parentCategories)
{
HttpContext.Current.Response.Write(parentCategory.CategoryName = "This should not happen");
BuildCategoryList(qryCategoryList, parentCategory.CategoryId);
}
Эта строка
HttpContext.Current.Response.Write(parentCategory.CategoryName = "This should not happen");
выполняет это
UPDATE Categories
SET ParentCategoryId = NULL /* @p0_0 */,
CategoryName = '->' /* @p1_0 */,
CategoryDescription = 'The Fruit Category' /* @p2_0 */,
Active = 1 /* @p3_0 */,
DateCreated = '2012-01-20T12:03:41.00' /* @p4_0 */,
LastUpdated = '2012-01-20T12:03:41.00' /* @p5_0 */
WHERE CategoryId = 'aa8ca9ba-663c-45c8-950b-159a28e6635d' /* @p6_0 */
Я не звоню сохранить из своего репозитория, не желая делать обновление. Как это возможно?
РЕДАКТИРОВАТЬ: Вот отображение
public class CategoryMap : ClassMap<Category>
{
public CategoryMap()
{
Table("Categories");
LazyLoad();
Id(x => x.CategoryId).GeneratedBy.GuidComb().Column("CategoryId");
Map(x => x.ParentCategoryId).Column("ParentCategoryId");
Map(x => x.CategoryName).Column("CategoryName").Not.Nullable().Length(50);
Map(x => x.CategoryDescription).Column("CategoryDescription").Not.Nullable();
Map(x => x.Active).Column("Active").Not.Nullable();
Map(x => x.DateCreated).Column("DateCreated").Not.Nullable();
Map(x => x.LastUpdated).Column("LastUpdated").Not.Nullable();
HasMany(x => x.PostingsCategories).KeyColumn("CategoryId");
}
}