如何映射的IDictionary<字符串,实体GT;在功能NHibernate [英] How to map IDictionary<string, Entity> in Fluent NHibernate
问题描述
可能重复:结果
的使用组件作为功能NHibernate
我有一个IDictionary的类就可以了。
I have an class with an IDictionary on it.
<map name="CodedExamples" table="tOwnedCodedExample">
<key>
<column name="OwnerClassID"/>
</key>
<index type="string" column="ExampleCode"/>
<many-to-many class="CodedExample" column ="CodedExampleClassID"/>
</map>
,你可以看到它采用的是多到了许多从使用其表的CodedExamples tOwnedCodedExample表中查找这是由OwnerClass拥有。
as you can see it uses a many-to-many to get the CodedExamples from their table using the tOwnedCodedExample table to find which are owned by the OwnerClass.
我意识到这是一个非常基本的(希望标准)的映射,但我在努力,并不能找到任何文件它,因此会很感激的任何可能的帮助。
I realise that this is a very basic (and hopefully standard) mapping but am struggling and can't find any documentation for it, therefore would be very grateful of any help possible.
非常感谢
斯图
推荐答案
我有一个工作的例子,这应该说清楚你的。
I have a working example, this should make it clear to you.
类:
public class Customer : Entity
{
public IDictionary<string, Book> FavouriteBooks { get; set; }
}
public class Book : Entity
{
public string Name { get; set; }
}
和则图:
HasManyToMany<Book>(x => x.FavouriteBooks)
.Table("FavouriteBooks")
.ParentKeyColumn("CustomerID")
.ChildKeyColumn("BookID")
.AsMap<string>("Nickname")
.Cascade.All();
生成的XML:
Resulting xml:
<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>
生成的SQL:
Generated SQL:
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")
)
这篇关于如何映射的IDictionary<字符串,实体GT;在功能NHibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!