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

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

问题描述

给定以下类定义:

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



$ b我有这个(流利的)映射

 参考文献(x => x.Product,ProductId); 

得到这个异常:Orders表中的一个关联指的是一个未映射的类,它不知道我将传递给它的实现。

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



谢谢,

Kyle

IProduct
而不是具体的类产品 C>。 (注意,我不是在讨论映射类 Order Product 字段。)


given the following class definition:

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

I have this (fluent) mapping

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

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.

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.

Thanks,

Kyle

解决方案

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天全站免登陆