How to transfer instances of anonymous types through NHibernate?

Intuitively, I would say that this is impossible, since NHibernate needs to know some cartographic information on how to save this type. So I came across some situations in which I could use such a function. For example, through a named query or something like this. On the other hand, using a named query will require me to add it to the configuration file.

Suppose we have an application that interacts with some basic data store. This data warehouse is configured through the NHibernate configuration file. Then I want NHibernate to load only a subset of the properties of an entity from another subsystem that did not need to interact much with my application, so you should not define classes for this system, since I only need part of this foreign system information, say, three out of thirty two columns of data. In this case, if I decided to load only those three columns, let me talk about performance problems, I would use an anonymous type, perform the required action on this information, and then return to the data store again. Now it would not be very interesting to do this if I had only one entity to load from the data warehouse,so let's say I have about 75,000 lines to load into my process. Then I will consider this option of the subset very seriously!

What strategy should you choose in such a situation if you need to transfer these changes to a subset of only these properties of the object?

FYI: I ask, because I have to write specific rules for use with NHibernate, such rules that even a novice developer could even use without knowing too much about NHibernate, but only following the rules and directions of the technical documents that I have to present.

Thanks in advance for any comments and answers.

+3
source share
1 answer

There are two approaches to this.

-, , select new HQL. , , .

.

, Images, , , . Length, ContentType, CreatedOn, Content, Description .

, . . , , , select new . :

class ImageMetadata
{
    public string ContentType { get; set; }
    public string Description { get; set; }

    // Etc
}

class Image : ImageMetadata
{
    // To native English speakers out there: is it "Content" or "Contents"?
    public byte[] Content { get; set; }
}

ImageMetadata, Image .

, , .

75 000 : ORM .

+1

Source: https://habr.com/ru/post/1732568/


All Articles