It drives me crazy. I can get one of the collections to save in the class, but not in the other.
I have a class called Category
public Category() { Items = new List<Item>(); Prices = new List<Price>(); }
These are two of these methods that are pretty much identical. Constructors define a property called Category , and their Name and Price respectively.
public virtual Item AddItem(string name) { var item = new Item(this, name); Items.Add(item); return item; } public virtual Price AddPrice(decimal price) { var price = new Price(this, price); Prices.Add(price); return price; }
Mappings
public class CategoryMap : ClassMap<Category> { public CategoryMap() {
As you can see, the two collections are displayed in exactly the same way.
Maps for Price and Item have the same display.
References(x=>x.Category);
As far as I can tell, almost all of the two are the same. Here is the problem
category.AddItem(someName); session.Save(category);
These are the files that I use to populate the test database. Saving an item works great. Saving prices - no. Classes and mappings are identical. I can not understand.
Mappings should work fine, as the constructor call directly works fine
session.Save(new Price(category, 1));
So why does a category save one collection and not another? I ran the profiler and the class didnβt even try to save the price collection.
Update:
As Gabe notes in a comment, if I swap calls so that the price is called before the item, the price goes to the database, and the item does not.
If I call session.Flush() after each collection update, it works fine. Do I have to do this, or is there a way to fix my mapping so that it works?