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 8980479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:05:55+00:00 2026-06-15T20:05:55+00:00

Is it possible to convert this code at below, written by using Query(linq) api

  • 0

Is it possible to convert this code at below, written by using Query(linq) api to Criteria or QueryOver API in NHibernate? I’m using this to format data into DTO’s also it works with just one round-trip to db.

Note: I tried transformers.aliastobean but I can only use one transformer at a time. Is it possible to use multiple transformer in one query?

     from entityType in Provider.GetSession().Query<crmEntityType>()
     .Fetch(x => x.Association)
     .Fetch(x => x.Fields)
     .AsEnumerable()
     where instanceIDs.Contains(entityType.Instance.instanceID)
     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();
  • 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-15T20:05:56+00:00Added an answer on June 15, 2026 at 8:05 pm

    Let’s start with the QueryOver syntax:

    // external filter data
    instanceIDs = new int[] { 1, 2, 3 };
    
    // aliasing
    EntityTypeDTO entityDTO = null;
    CustomFieldDTO fieldDTO = null;
    Field field = null;
    
    IQueryOver<EntityType, Field> query = Session.QueryOver<EntityType>()
    
      // filter Entity by ID's list
      .Where(Restrictions.On<EntityType>(c => c.ID).IsIn(instanceIDs))
    
      // Join Fields
      .JoinQueryOver<Field>(c => c.Fields, () => field)
      .SelectList(list => list
    
        // entity
        .Select(c => c.ID)
        .Select(c => c.Title)
        // ... more Entity properties
    
        // field collection
        .Select(() => field.ID)
        .Select(() => field.Name)
        // ... more Field properties
      )
      .TransformUsing(new MyTransformer()); // see below
    
    var dtos = query.List<EntityTypeDTO>();
    

    This QueryOver will generate the SQL statement which will contain all EntityTypes with their Fields. Now we have to extract the unique EntityType instances and fill their Fields lists

    There is an overview of DTO classes (as well as QueryOver above, these contain only ver few properties as an example):

    public class EntityTypeDTO
    {
      public virtual int ID { get; set; }
      public virtual string Title { get; set; }
      public virtual IList<CustomFieldDTO> Fields { get; set; }
      ...
    }
    public class CustomFieldDTO 
    {
      public virtual int ID { get; set; }
      public virtual string Name { get; set; }
      ...
    }
    

    And finally the trick MyTransformer():

    public class MyTransformer : IResultTransformer
    {
      // rows iterator
      public object TransformTuple(object[] tuple, string[] aliases)
      {
        var entity = new EntityTypeDTO
        {
          ID = (int)tuple[0],         // aliases should be used
          Title = tuple[1] as string  // first two are belong to Entity
        };
        var field = new CustomFieldDTO
        {
          ID = (int)tuple[2],         // last 2 columns are for a Field
          Name = tuple[3] as string   // see SelectList in QueryOver
        };
        entity.Fields = new List<CustomFieldDTO> { field };
        return entity;
      }
    
      // convert to DISTINCT list with populated Fields
      public System.Collections.IList TransformList(System.Collections.IList collection)
      {
        var results = new List<EntityTypeDTO>();
        foreach(var item in collection)
        {
          var entity = item as EntityTypeDTO;
    
          // was already the same ID appended
          var existing = results.SingleOrDefault(c => c.ID.Equals(entity.ID));
          if(existing != null)
          {
            // extend fields
            existing.Fields.Add(entity.Fields.First());
            continue;
          }
    
          // new ID found
          results.Add(entity);
        }
        // DISTINCT list of Entities, with populated FIELDS
        return results;
      }
      ...
    

    MyTransformer is ad hoc one, only for this purpose… but this approach could be extended

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wanting to know if it is possible to convert this code below, so
Is it possible to convert this java code snippet to php? public void testBalanceReturnsToZeroOnVending()
I am trying to convert the code below to a shorthand linq, but not
Is it possible to convert this if statement into a one line statement ?
Is it possible to convert facebook data (ex. user_pic) into a DisplayObject so I
I have the below code written in php and have been reading up on
I am trying to create a CSV file using the C# code below: string
i tried the code below to convert it to c#. But i am getting
In the code below I am building data up in a nested list. After
I am trying to fetch the below json content using a magazine api. The

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.