简体   繁体   English

过滤对象OnLoad NHibernate IInterceptor

[英]Filtering objects OnLoad NHibernate IInterceptor

I am having a problem loading objects using NHibernate. 我在使用NHibernate加载对象时遇到问题。 These entities have reference to files which no longer exist. 这些实体引用了不再存在的文件。 When NHibernate assigns the 'Path' property of these entities these entities try to load the file which results in a an exception. 当NHibernate为这些实体分配“ Path”属性时,这些实体会尝试加载文件,从而导致异常。 The exception causes the loading transaction to roll-back completely. 异常导致加载事务完全回滚。

I would like to keep my entities unchanged so they keep loading the file once Path is set. 我想保持我的实体不变,因此一旦设置了路径,它们就会继续加载文件。 In the case that I am loading from DB i would like to skip these entities and load the rest of my project. 在我从数据库加载的情况下,我想跳过这些实体并加载项目的其余部分。

I was thinking about using an IInterceptor to get this done. 我正在考虑使用IInterceptor来完成此操作。 Basiccally i would like to filter my file based objects before I load them. 基本上,我想在加载基于文件的对象之前对其进行过滤。

I would like to hear any thoughts about similar problems and whether my 'solution' is feasible and possible. 我想听听有关类似问题的任何想法,以及我的“解决方案”是否可行和可能。

Greetings, Martijn Martijn,问候

Try File.Exists(path) before loading the file ? 在加载文件之前尝试File.Exists(path)吗? Not sure I understood the problem. 不确定我是否了解问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM