views:

21

answers:

0

At Same table I Have 2 Objects: Product, ProductDetail

public class Product
{
    public virtual int ID {get;set;}

    public virtual string Name {get;set;}

    public virtual Detail {get;set;}
}

public class ProductDetail
{
    public virtual int ID {get;set;}

    public virtual string Title {get;set;}

    public virtual Product Product {get;set;}
}

I Using Fluent Mappings:

public ProductMap() : ClassMap<Product>
{
    public ProductMap()
    {
        Id(p => p.ProductID).GeneratedBy.Native();
        Map(p => p.Name);
        HasOne<ProductDetail>(p => p.Detail).Cascade.All();
    }
}

public ProductDetailMap() : ClassMap<ProductDetail>
{
    public ProductDetailMap()
    {
        Id(p => p.ProductID).ColumnName("ProductID").GeneratedBy.Foreign("Product");
        HasOne<Product>(p => p.Product).Cascade.All();
        Map(p => p.Title);
    }    
}

ok, I want to Create New Product Data:

Product product = new Product()
{
    Name = "Test New Product1",
};

ProductDetail detail = new ProductDetail()
{
    Title = "Detail Title"
};

detail.Product = product;
product.Detail = detail;

session.Save(product)
//session.Save(detail);

Product and ProductDetail At same table ,I want to created new Product,create ProductDetail, also is Update the product row.

Anyone got any ideas?

Thanks

James.Ying