你如何映射一个实体 ->使用 Fluent NHibernate 的接口关系? [英] How do you map an entity -> interface relationship using Fluent NHibernate?

查看:25
本文介绍了你如何映射一个实体 ->使用 Fluent NHibernate 的接口关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定以下类定义:

public class Order {
  public IProduct Product {get;set;}
}

我有这个(流畅的)映射

I have this (fluent) mapping

References(x=>x.Product, "ProductId");

并得到这个异常:Orders 表中的关联引用了一个未映射的类,这是有道理的,因为它不知道我将传递给它什么实现.

And get this exception: An association from the table Orders refers to an unmapped class, which makes sense because it doesn't know what implementation I will pass to it.

我明白为什么我必须在映射中定义类型(IProduct 可以是任何东西),但我不知道如何去做.

I understand why I have to define the type in the mapping (IProduct could be anything) but I'm not sure how to do it.

谢谢,

凯尔

推荐答案

尝试映射接口 IProduct 而不是具体的类 Product.(注意,我不是在谈论映射 Order 类的 Product 字段.)

Try mapping the interface IProduct instead of the concrete class Product. (Note, I'm not talking about mapping the Product field of class Order.)

这篇关于你如何映射一个实体 ->使用 Fluent NHibernate 的接口关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆