How to bind a series of columns into a collection with NHibernate

血红的双手。 提交于 2019-12-25 01:52:39

问题


Please believe me when I say I understand this isn't the "right" way to do this. File this under large-complex-legacy-system questions.

We have tables describing OCR'd data of documents. Each document type has its own table. Each table is generated based on the types of fields it expects. So have a schema which looks a bit like this:

Table: DocumentTypes
   Field: Id
   Field: Prefix

Table: DocumentFields
   Field: Id
   Field: DocId
   Field: Name

And we would generate tables like:

Table: Type1_Data_Unit1000
   Field: Id
   Field: DocId
   Field: DocField_A_Data
   Field: DocField_A_Info1
   Field: DocField_A_Info2
   Field: DocField_Z_Data
   Field: DocField_Z_Info1
   Field: DocField_Z_Info2

NHibernate works well for all of our other data because the schema is more static.

My question: Is it at all possible to configure nhibernate to load one of the DataTables and bind the series of fields into a collection? If it is, at what interfaces should I start looking?

My idea is to have a class which is something like:

class FormData
{
   public virtual int Id {get;set;}
   public virtual int DocId {get;set;}
   public virtual int Id {get;set;}
   public virtual IList(Of FormFieldData) {get;private set;}
}

class FormFieldData
{
   public virtual int Id {get;set;}
   public virtual string Value {get;set;}
   public virtual int Info1 {get;set;}
   public virtual int Info2 {get;set;}
}

I've looked at "IInterceptor" a little bit and think that's where I should look first. But before investing days in it, I wanted to run it by the SO crowd.

Thanks!


回答1:


If the schema isn't static, then it'll be hard for nhibernate to even create the query - and intercepters can't help you there as far as I'm concerned. I'd go with pure CreateSQLQuery and manipulating the returned values manually afterwards.



来源:https://stackoverflow.com/questions/1155006/how-to-bind-a-series-of-columns-into-a-collection-with-nhibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!