Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.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
C# 如何映射IDictionary<;字符串、实体>;以流利的语言_C#_Nhibernate_Fluent Nhibernate_Nhibernate Mapping - Fatal编程技术网

C# 如何映射IDictionary<;字符串、实体>;以流利的语言

C# 如何映射IDictionary<;字符串、实体>;以流利的语言,c#,nhibernate,fluent-nhibernate,nhibernate-mapping,C#,Nhibernate,Fluent Nhibernate,Nhibernate Mapping,我有一节课上有一本词典 <map name="CodedExamples" table="tOwnedCodedExample"> <key> <column name="OwnerClassID"/> </key> <index type="string" column="ExampleCode"/> <many-to-many class="CodedExample" colum

我有一节课上有一本词典

  <map name="CodedExamples" table="tOwnedCodedExample">
    <key>
      <column name="OwnerClassID"/>
    </key>
    <index type="string" column="ExampleCode"/>
    <many-to-many class="CodedExample" column ="CodedExampleClassID"/>
  </map>

如您所见,它使用多对多从表中获取CodedExample,使用tOwnedCodedExample表查找OwnerClass所拥有的

我意识到这是一个非常基本的(希望是标准的)映射,但我很努力,找不到任何文档,因此非常感谢任何可能的帮助

非常感谢


斯图

我有一个有效的例子,这应该让你明白

课程:

public class Customer : Entity
{        
    public IDictionary<string, Book> FavouriteBooks { get; set; }
}

public class Book : Entity
{
    public string Name { get; set; }
}

book.name
映射为键,而不是昵称。

它不是重复的。问题是不同的。谢谢保罗,问题是非常不同的。我的另一个问题是关于字典索引的复合键,我希望这是一个关于FluentNH中字典的标准用法的更简单的问题。保罗,你知道怎么画地图吗?我看到很多帖子都说这是可能的,但没有一篇能说明这是怎么回事!看起来不错,谢谢。我明天到办公室再打给你,我会试试的。谢谢保罗,这工作做得很好。不幸的是,这个问题已经作为一个重复的问题被关闭,但希望它仍然会出现在搜索结果中,以便其他人可以使用它作为一个例子。干杯,斯图
HasManyToMany<Book>(x => x.FavouriteBooks)
            .Table("FavouriteBooks")                
            .ParentKeyColumn("CustomerID")
            .ChildKeyColumn("BookID")
            .AsMap<string>("Nickname")                
            .Cascade.All();
<map cascade="all" name="FavouriteBooks" table="FavouriteBooks" mutable="true">
  <key>
    <column name="`CustomerID`" />
  </key>
  <index type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <column name="`Nickname`" />
  </index>
  <many-to-many class="Domain.Book, Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
    <column name="`BookID`" />
  </many-to-many>
</map>
create table "Customer" (
    "Id"  integer,
   "FirstName" TEXT,
   primary key ("Id")
)

create table FavouriteBooks (
    "CustomerID" INTEGER not null,
   "BookID" INTEGER not null,
   "Nickname" TEXT not null,
   primary key ("CustomerID", "Nickname")
)

create table "Book" (
    "Id"  integer,
   "Name" TEXT,
   primary key ("Id")
)