public static AssociatedType GetAssociatedObject(ISession session, string table, int id) { return((AssociatedType)TransitObject.GetRandomElement <AssociatedType>( session.CreateCriteria(typeof(AssociatedType)) .Add(Expression.Eq(string.Format("{0}.Id", table), id)) .List <AssociatedType>())); }
public TransitPost(ISession session, DBlog.Data.Post o, bool hasaccess) : base(o.Id) { Title = o.Title; Slug = o.Slug; HasAccess = hasaccess; if (hasaccess) { mRawBody = o.Body; Body = Render(session, o.Body); BodyXHTML = RenderXHTML(session, o); } LoginId = o.Login.Id; if (o.PostImages != null && o.PostImages.Count > 0) { ImagesCount = o.PostImages.Count; if (hasaccess) { ImageId = ((PostImage)TransitObject.GetRandomElement(o.PostImages)).Image.Id; } } // topics List <TransitTopic> topics = new List <TransitTopic>(); if (o.PostTopics != null) { foreach (PostTopic postTopic in o.PostTopics) { topics.Add(new TransitTopic(postTopic.Topic)); } } mTopics = topics.ToArray(); Created = o.Created; Modified = o.Modified; CommentsCount = new CountQuery(session, typeof(PostComment), "PostComment") .Add(Expression.Eq("Post.Id", o.Id)) .Execute <int>(); Counter = TransitCounter.GetAssociatedCounter <Post, PostCounter>( session, o.Id); Publish = o.Publish; Display = o.Display; Sticky = o.Sticky; Export = o.Export; }