Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fluent nhibernate FluentNhibernate具有多个关系-它不会添加到链接表中_Fluent Nhibernate - Fatal编程技术网

Fluent nhibernate FluentNhibernate具有多个关系-它不会添加到链接表中

Fluent nhibernate FluentNhibernate具有多个关系-它不会添加到链接表中,fluent-nhibernate,Fluent Nhibernate,使用fluentnhibernate时,我遇到了链接表插入问题 这是我的实体 public partial class Item { public virtual int Id { get; set; } public virtual string Description { get; set; } public virtual IList<Category> C

使用fluentnhibernate时,我遇到了链接表插入问题

这是我的实体

public partial class Item
{
    public virtual int Id
    {
        get;
        set;
    }

    public virtual string Description
    {
        get;
        set;
    }
    public virtual IList<Category> Categories
    {
        get;
        set;
    }
}
public partial class Category
{
    public virtual int Id
    {
        get;
        set;
    }

    public virtual string Name
    {
        get;
        set;
    }
    public virtual string Description
    {
        get;
        set;
    }
    public virtual IList<Item> Items
    {
        get;
        set;
    }
}
这是我的映射

public class ItemMapping : ClassMap<Item>
{
    public ItemMapping()
    {
        Table("Item");
        Schema("dbo");
        Id(x => x.Id);
        Map(x => x.Description);
        HasManyToMany(x => x.Categories)
            .ChildKeyColumn("Item_id")
            .ParentKeyColumn("Category_id")
            .Table("CategoriesToItems")
            .AsSet();
        }
}

    public class CategoryMapping : ClassMap<Category>
{
    public CategoryMapping()
    {
        Table("Category");
        Schema("dbo");
        Id(x => x.Id);
        Map(x => x.Description);
        Map(x => x.Name);
        HasManyToMany(x => x.Items)
            .ChildKeyColumn("Category_id")
            .ParentKeyColumn("Item_id")
            .Table("CategoriesToItems")
            .AsSet();
    }
}
下面是我如何将其添加到mvc页面中的集合

var category = CategoryTask.Query(x => x.Id == post.Category).FirstOrDefault();

var item = new Item
                {
                    Categories = new List<Category> { category },
                    Tags = tags   
                };
ItemTasks.Save(item);
我的问题是为什么它不在我的链接表CategoriesToItems中添加关系。该表已在数据库中,其类别为_idfk,int,not null,项为_idfk,int,not null


问题在哪里?为什么不将其添加到关系表中?

当我们看不到您的ItemTasks.Save在封面下做了什么时,很难说到底出了什么问题。您是否在事务中包装您的存储?如果没有,您应该是。

您应该在事务之前调用Session.Flush。同时提交。

我不确定问题是否已解决,但它看起来与我的问题类似


而且,您的父键列和子键列看起来是向后的。

是的。我用NCommon来做这个。保存调用在NCommon中保存IRepository的方法。