NHibernate Isession管理

时间:2021-09-21 10:43:24

一个Session

 foreach (var item in favoriteId)
{
if (!string.IsNullOrEmpty(item))
{
var favorite = _session.Get<Favorite>(Guid.Parse(item));
if (favorite != null)
{
// 删除资源
var favoriteList = _session.CreateCriteria<Favorite>().Add(Restrictions.Eq("ResId", favorite.ResId)).List();
if (favoriteList != null && favoriteList.Count <= )
{
_session.Delete(new FavoriteResourceInfo { ResId = favorite.ResId });
}
// 删除关联
var favoriteLabelList = _session.CreateCriteria<FavoriteLabel>().Add(Restrictions.Eq("FavoriteId", Guid.Parse(item))).List<FavoriteLabel>(); //relationResponse.GetRelationByFavoriteId(Guid.Parse(item));
if (favoriteLabelList != null && favoriteLabelList.Count > )
foreach (var favoriteLabel in favoriteLabelList)
{
_session.Delete(favoriteLabel);
}
// 删除收藏
_session.Delete(favorite);
}
}