You are not setting forum.Category.

    Diego


On Thu, Aug 12, 2010 at 15:09, [email protected] <
[email protected]> wrote:

> The code below demonstrates a problem I am having with my entities and
> their mappings. I have stripped down the code for clarity, keeping
> only the relavent parts. I have tried all possible combinations of
> Cascase and inverse to no avail. Please take a look and see if anybody
> can spot my error.
>
> CATEGORY
>
> public class Category : Entity
> {
> private IList<Forum> forums = new List<Forum>();
> public virtual IEnumerable<Forum> Forums { get { return forums; } }
> public virtual void AddForum(Forum forum)
> {
> if (!forums.Contains(forum)) forums.Add(forum);
> }
> }
>
> FORUM
>
> public class Forum : Entity
> {
> // this is here to help my model builders create navigational
> // bits for the models passed into the views. I do not intend
> // on even manually changing the value of this property.
> // It is not passed in to the ctor nor is there a setter for it.
> public virtual Category Category { get; protected set; }
> }
>
> REFERENCE CONVENTION
>
> instance.Column(instance.Property.Name + "Id");
>
> HASMANYCONVENTION
>
> instance.Key.Column(instance.EntityType.Name + "Id");
> instance.Cascade.All();
>
> instance.Access.ReadOnlyPropertyThroughCamelCaseField(CamelCasePrefix.None);
>
> PROBLEM
>
> Category category = categoryRepository.SelectById(2); // this works
> Forum forum = new Forum("Sample Forum"); // this works
> category.AddForum(forum); // this APPEARS to work - it is added to the
> internal collection
> categoryRepository.Update(category); // this fails - cannot insert
> forum into table due to null CategoryId (field is preesent in actual
> table)
>
> How do I fix this?
>
> Thanks in advance, and if you have a solution for me, please try to
> explain why it works where mine does not. This way I actually learn
> something.
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
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/nhusers?hl=en.

Reply via email to