I've been wasting about 4 hours now, trying to solve a really weird problem
with Active Record. I'm building a forum, and I want to update the
Forum-entity, when a new ForumPost is being saved, so the number of posts
are correct. There are my classes (i've simplfied them a bit, just the
important stuff
[ActiveRecord(Lazy = true)]
public class Forum
{
[PrimaryKey(Generator = PrimaryKeyType.Identity)]
public virtual int Id { get; set; }
[Property]
public virtual int NumberOfPosts { get; set; }
[HasMany(typeof(ForumThread), Lazy = true, Inverse = true)]
public virtual IList<ForumThread> Threads { get; set; }
}
[ActiveRecord(Lazy = true)]
public class ForumThread
{
[PrimaryKey(Generator = PrimaryKeyType.Identity)]
public virtual int Id { get; set; }
[Property]
public virtual string Title { get; set; }
[BelongsTo]
public virtual Forum Forum { get; set; }
}
Somewhere in my program, is the following code (also simplified)
var thread = ActiveRecordMediator<ForumThread>.FindByPrimaryKey(id);
var forum = thread.Forum;
forum.NumberOfCodes = 9; //This value is being calculated
ActiveRecordMediator<Forum>.Save(forum);
To me, this looks very normal, but somehow the following error occurs:
*You have accessed an ActiveRecord class that wasn't properly initialized.
There are two possible explanations: that the call to
ActiveRecordStarter.Initialize() didn't include ForumProxy class, or that
ForumProxy class is not decorated with the [ActiveRecord] attribute.*
Ehm, WHY? I really have now idea how this is possible. All the entities are
properly initialized in the Global.asax (a lot of other things are working
correct). I assume the Forum is Lazy loaded, and therefor a Proxy, but why
doesn't the program know it's a proxy? How am I suppose to make the code
work? I know setting Forum as Lazy = false works, but I don't want that..
Hope someone can help. I'm using all the latest versions, loaded via NuGet.
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/castle-project-users/-/YlnSNRRUK_4J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en.