果园自定义模块 - 型号被拾起NHibernate的 - 要求虚拟财产 [英] Orchard Custom Module - Model being picked up by NHibernate - Requiring virtual properties

查看:72
本文介绍了果园自定义模块 - 型号被拾起NHibernate的 - 要求虚拟财产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作在果园CMS构建自定义模块,并且我有以下控制器动作:

I'm working on building a custom module in Orchard CMS, and I have the following Controller Action:

public ActionResult Inventory()
{
   var models = _repository.Get<MyModel>();
   return View(new MyViewModel() { MyModels = models.ToList() });
}

现在,果园建立这个时候,发生了异常,因为NHibernate的回升为MyModel因为它被看作为一个PartRecord,我不希望它是。

Now, when Orchard builds this, an exception occurs, because NHibernate has picked up MyModel because its being looked at as a PartRecord, which I do not want it to be.

唯一的例外是方法get_Id应该是公共/受保护的虚拟或受保护的内部虚拟。

The exception is method get_Id should be 'public/protected virtual' or 'protected internal virtual'.

我可以添加虚拟的属性,但我想避免NHibernate的任何部分在寻找这个对象,这是不必要的。

I can add virtual to the properties, but I want to avoid having NHibernate have any part in looking at this object, it is unnecessary.

我的问题是,我怎么可以添加一个型号,访问模型视图和SUP preSS果园把它当作一个PartRecord?实际上我用的模型在一个单独的存储库中,从乌节DB分开。

My question is, how can I add a Model, access that model in a view and suppress Orchard from treating it as a PartRecord? I actually use the model in a separate repository, separate from the Orchard DB.

编辑:附加信息

_repository是IDbRepository,指着我自己的数据库实例
为MyModel是我的数据的POCO。我试图避免将虚拟在为MyModel的属性,我有他们在这里,来说明在那里我试图避开他们。

_repository is an IDbRepository, pointing to my own DB instance MyModel is a POCO for my data. I'm trying avoid putting virtual on the properties in MyModel, I have them in here, to illustrate where I'm trying to avoid them.

public interface IDbRepository : IDependency
{
    T Find<T>(long id) where T : class, IActiveRecord;
    bool Update<T>(T record) where T : class, IActiveRecord;
    bool Remove<T>(T record) where T : class, IActiveRecord;
}

public class MyModel : IActiveRecord
{
    [Key]
    public virtual long Id { get; set; }
    public virtual int SupplierProductId { get; set; }
    public virtual int SupplierId { get; set; }
    public virtual int ProductId { get; set; }
}

除了这个,我的模块确实有,我已经创建了一个设置的一部分,这并获取存储在乌节DB和站点设置中编辑。我使用一个处理程序来控制。不过,我试图消除处理程序和其他几件事情,以保持果园采取我的对象到NHibernate的。

In addition to this, my module does have a settings part that I've created, that does get stored in Orchard DB and is edited in the site settings. I'm using a handler to control that. However, I've tried removing the handler and a few other things to keep Orchard from taking my object into NHibernate.

推荐答案

果园自动映射配置假定如果满足以下条件,任何类将被映射:

Orchard auto-mapping configuration assumes that any class will be mapped if the following conditions are met:


  • 的命名空间.Models或.Records结尾

  • 有一个编号属性,虚拟访问

  • 类既不密封,也没有抽象

  • 类没有实施 IContent 或继承 ContentPartRecord

  • the namespace ends with ".Models" or ".Records"
  • there is an Id property, with virtual accessors
  • the class is neither sealed nor abstract
  • the class doesn't implement IContent or inherits from ContentPartRecord

所以,如果你prevent任何被真正的这些标准,你应该不错。例如,定义命名空间中的不结束你的类 .Models .Records 应该足够了。

So if you prevent any of those criteria from being true, you should be good. For instance, defining your classes in a namespace not ending with .Models or .Records should be sufficient.

这篇关于果园自定义模块 - 型号被拾起NHibernate的 - 要求虚拟财产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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