Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8966353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:00:34+00:00 2026-06-15T17:00:34+00:00

I have a problem with NHibernate for a longtime which I solved by non-optimal

  • 0

I have a problem with NHibernate for a longtime which I solved by non-optimal ways/workarounds.

First of all, I’m using WCF REST to communicate with my client application. As you know, serializing persisted entities is not a best practise and always causes other problems. Thus, I always map my entities to DTO’s with NHibernates Transformers. The problem is that I have entities which are more complex to use Transformers to convert them.

How can I map sub entities to sub dto’s by using transformers or any other nhibernate feature?

Note: I don’t want to use 3rd parties like Automapper.

These are the Entities and DTO’s which I want to map. Variable names are exactly same with each other.

Entity Classes:

EntityType

public class crmEntityType : EntityModel<crmEntityType>
{
    public crmEntityType()
    {
        Association = new List<crmEntityType>();
        Fields = new List<crmCustomField>();
    }

    public virtual int ID { get; set; }

    public virtual string Title { get; set; }

    public virtual ICollection<crmEntityType> Associations { get; set; }

    public virtual ICollection<crmCustomField> Fields { get; set; }

}

CustomFields

    public class crmCustomField : EntityModel<crmCustomField>
{
    public virtual int ID { get; set; }

    public virtual string Name { get; set; }

    public virtual crmEntityType EntityType { get; set; }
}

DTO’s

EntityTypeDTO

[DataContract]
public class EntityTypeDTO
{
    [DataMember]
    public int ID { get; set; }

    [DataMember]
    public string Title { get; set; }

    [DataMember]
    public IList<CustomFieldDTO> Fields { get; set; }

    [DataMember]
    public int[] Associations { get; set; }
}

CustomFieldDTO

[DataContract]
    public class CustomFieldDTO
{
    [DataMember]
    public int ID { get; set; }

    [DataMember]
    public string Name { get; set; }

    [DataMember]
    public int EntityType { get; set; }

    [DataMember]
    public int FieldType { get; set; }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:00:35+00:00Added an answer on June 15, 2026 at 5:00 pm

    I found my solution by spending my day and night to work it out. Finally, I’ve got the best solution I could find. I hope it helps someone in my condition some day.

    This linq query works with just one database round-trip. I think it maps the classes in memory.

    return (from entityType in Provider.GetSession().Query<crmEntityType>()
                    .Fetch(x => x.Association)
                    .Fetch(x => x.Fields)
                    .AsEnumerable()
        select new EntityTypeDTO()
        {
            ID = entityType.ID,
            Title = entityType.Title,
            Association = entityType.Association.Distinct()
                                   .Select(asc => asc.ID).ToArray<int>(),
            Fields = entityType.Fields.Distinct()
                                   .Select(fi => new CustomFieldDTO 
                                                { ID = fi.ID, 
                                                  Name = fi.Name, 
                                                  Value = fi.Value, 
                                                  EntityType = fi.EntityType.ID,
                                                  Type = fi.Type 
                                                }).ToList()
        }).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem using Linq to NHibernate to load an object and eagerly
I query my NHibernate datasources using a Linq Expression. The problem I have with
I have a class that is mapped to a table using NHibernate. The problem
Using MVC3 with NHibernate, I am having a problem with dropdowns. I have a
i have a problem with my first app with NHibernate like ORM in this
I have a problem using QBE with NHibernate. Here's a sample code: Person person
I have an NHibernate problem with lists, which are mapped as subclasses of an
I have problem using Fluent Nhibernate, I have following model. When I try to
I have a problem with NHibernate not using my mappings configuration for eager loading
I have problem with perfomance in my website. I am using NHibernate to retrieve

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.