internal TaxonomyNode(TaxonomyTree tree, TaxonEntity entity) { this.tree = tree; this.entity = entity; this.IsDetached = false; //tree.log.Debug("Node init:" + Name); }
public void TestRelationCrud() { var taxonRepo = Container.Resolve<TaxonRepository>(); var taxon1 = new TaxonEntity(); taxon1.Name = "Test1"; taxonRepo.SaveOrUpdate(taxon1); var taxon2 = new TaxonEntity(); taxon2.Name = "Test2"; taxonRepo.SaveOrUpdate(taxon2); var taxon3 = new TaxonEntity(); taxon3.Name = "Test3"; taxonRepo.SaveOrUpdate(taxon3); var taxon4 = new TaxonEntity(); taxon4.Name = "Test4"; taxonRepo.SaveOrUpdate(taxon4); var relationService = Container.Resolve<RelationService>(); //relationService.Relate(taxon1, taxon2, RelationDirection.Both); //relationService.Relate(taxon1, taxon2, RelationDirection.Forward); relationService.AddRelation(taxon1, taxon3, RelationDirection.Forward); relationService.AddRelation(taxon1, taxon3); //relationService.Relate(taxon3, taxon4, RelationDirection.Both); }
public IList <RelationEntity> GetRelationsByType(TaxonEntity taxonEntity) { using (var wu = SessionManager.WorkUnitFor(this, DbWorkUnitType.Read)) { var ret = this.AsQueryable(wu.Session) .Where(x => x.Type == taxonEntity); return(ret.ToList()); } }
public static RelationEntity Create(IClassifiable relatable, IClassifiable related, TaxonEntity type = null, RelationDirection direction = RelationDirection.Undefined) { return new RelationEntity() { Type = type, Direction = direction, ObjectName = relatable.ObjectName, ObjectID = relatable.Id, RelatedObjectName = related.ObjectName, RelatedObjectID = related.Id, }; }
public void TestTaxonCrud() { var taxonRepo = Container.Resolve<TaxonRepository>(); var taxon = new TaxonEntity(); taxon.Name = "aaa"; taxonRepo.SaveOrUpdate(taxon); var persistentTaxon = taxonRepo.Get(taxon.Id); taxonRepo.Delete(taxon); var deletedTaxon = taxonRepo.Get(taxon.Id); Assert.IsNull(deletedTaxon); }
public static RelationEntity Create(IClassifiable relatable, IClassifiable related, TaxonEntity type = null, RelationDirection direction = RelationDirection.Undefined) { return(new RelationEntity() { Type = type, Direction = direction, ObjectName = relatable.ObjectName, ObjectID = relatable.Id, RelatedObjectName = related.ObjectName, RelatedObjectID = related.Id, }); }
public IList <RelatedIdsResult> GetByRelatedIds(IClassifiable classifiable, RelationDirection direction = RelationDirection.Undefined, TaxonEntity type = null) { if (classifiable == null) { log.Warn("GetByRelatedIds null request"); return(null); } using (var wu = SessionManager.WorkUnitFor(this, DbWorkUnitType.Read)) { var criteria = CreateGetByRelatedCriteria(wu, classifiable, direction, type) .SetProjection(Projections.ProjectionList() .Add(Projections.Property("ObjectID"), "Id") .Add(Projections.Property("ObjectName"), "Name")) .SetResultTransformer(new AliasToBeanResultTransformer(typeof(RelatedIdsResult))); return(criteria.List <RelatedIdsResult>()); } }
private ICriteria CreateGetByRelatedCriteria(DbWorkUnit wu, IClassifiable classifiable, RelationDirection direction = RelationDirection.Undefined, TaxonEntity type = null) { var criteria = wu.Session.CreateCriteria <RelationEntity>() .Add(Restrictions.Eq("RelatedObjectName", classifiable.ObjectName)) .Add(Restrictions.Eq("RelatedObjectID", classifiable.Id)); if (type != null) { criteria.Add(Restrictions.Eq("Type", type)); } if (direction != RelationDirection.Undefined) { criteria.Add(Restrictions.Eq("Direction", (int)direction)); } return(criteria); }
public RelationEntity GetRelation(IClassifiable relatable, IClassifiable related, TaxonEntity type = null) { using (var wu = SessionManager.WorkUnitFor(this, DbWorkUnitType.Read)) { return(AsQueryable(wu.Session) .Where(x => x.RelatedObjectName == related.ObjectName && x.RelatedObjectID == related.Id) .Where(x => x.ObjectName == relatable.ObjectName && x.ObjectID == relatable.Id) .Where(x => x.Type == type) .FirstOrDefault()); } }
public IList <T> GetByRelated <T>(IClassifiable classifiable, RelationDirection direction = RelationDirection.Undefined, TaxonEntity type = null) where T : Entity, IClassifiable { List <T> ret = new List <T>(); using (var repo = new Repository <T>(context, log)) { var idList = GetByRelated(classifiable, direction, type).Select(y => y.ObjectID).ToList(); if (idList.Count() > 0) { using (var wu = SessionManager.WorkUnitFor(this, DbWorkUnitType.Read)) { ret = repo.AsQueryable(wu.Session).Where(x => idList.Contains(x.Id)).ToList(); } } ret.ForEach(x => repo.Evict(x)); } return(ret); }
public IList <RelationEntity> GetByRelated(IClassifiable classifiable, RelationDirection direction = RelationDirection.Undefined, TaxonEntity type = null) { if (classifiable == null) { log.Warn("GetByRelated null request"); return(null); } using (var wu = SessionManager.WorkUnitFor(this, DbWorkUnitType.Read)) { var criteria = CreateGetByRelatedCriteria(wu, classifiable, direction, type); return(criteria.List <RelationEntity>()); } }