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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:18:49+00:00 2026-06-16T04:18:49+00:00

I have a method in my repository to retrieve All records for Items public

  • 0

I have a method in my repository to retrieve All records for Items

public IQueryable<Item> GetAll()
        {
            //The following causes a circular reference if you attempt to serialize it via an API call.
            IQueryable<Item> items = context.Items.Include(c => c.UserProfile).Include(c => c.UserProfile1).AsQueryable();
            return items;
        }

This causes issues with Kendo Grid and serialization because of how I am including the foreign tables User Profile twice to be able to get the full name of the user whom created and modified the Item record.

Instead of Include(c => c.UserProfile) is there a way to only include the UserProfile.FullName column?

Today I am handling this in my ViewModel and creating a new subclass (this example is for Locations, not Items):

public class LocationsListViewModel
    {
        public IEnumerable<LocationsGrid> Locations { get; set; }
        public IEnumerable<Facility> Facilities { get; set; }
        public IEnumerable<string> AreaOptions { get; set; }
        public int LocationCount { get; set; }

        public class LocationsGrid
        {
            public int Id { get; set; }
            public string DisplayLocation { get; set; }
            public string Area { get; set; }
            public string Zone { get; set; }
            public string Aisle { get; set; }
            public string Bay { get; set; }
            public string Level { get; set; }
            public string Position { get; set; }
            public string Barcode { get; set; }

        }
    }

and then having to populate that in my Tasks or App Services layer (sits between controller and repository) like this:

viewModel.Locations = from l in locations.ToList()
select new LocationsListViewModel.LocationsGrid
{
   Id = l.Id,
   DisplayLocation = l.DisplayLocation,
   Area = l.Area,
   Zone = l.Zone,
   Aisle = l.Aisle,
   Bay = l.Bay,
   Level = l.Level,
   Position = l.Position,
   Barcode = l.BarcodeValue
};

This seems like a lot of extra code and maintenance for each entity going forward. I’m sure there is a more efficient way to do this.

  • 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-16T04:18:50+00:00Added an answer on June 16, 2026 at 4:18 am

    I typically use a Data-Transfer Object (basically just a class that has the exact data you’re looking for, then returning objects of that type from your data-access method.

        public IQueryable<ItemSummary> GetAll()
        {
            IQueryable<ItemSummary> items = context.Items
                .Select(c => new ItemSummary {
                       FirstProfileName = c.UserProfile.FullName,
                       SecondProfileName = c.UserProfile1.FullName,
                       ScalarProp1 = c.ScalarProp1,
                       ...
                    })
                .AsQueryable();
            return items;
        }
    

    I’m not sure if that will work the way you want it to, since I’m not familiar with Kendo Grid and such, but it may be useful.

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

Sidebar

Related Questions

I have a Repository Class with the following method... public T Single<T>(Predicate<T> expression) {
i have the following action method that calls a repository method:- public ActionResult Details(int
I have the following method inside my repository class, to retrieve a Session object
I have this method to get a generic repository out of a dictionary: public
I have the following method in my repository that returns a mix of two
I have the following action method that initiated SelectList as follow:- public PartialViewResult Search(string
I'm using NHibernate 3.2 and I have a repository method that looks like: public
I have the following DeletePOST action method:- [HttpPost] public ActionResult Delete(int id) { try
I have this method: public static Expression<Func<MyEntity, bool>> MyMethod(string someId) { return o =>
I have a controller method that acceses a repository method which has lambda expression

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.