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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:36:35+00:00 2026-05-21T19:36:35+00:00

I have a slightly obscure model in that Users come from Active Directory, but

  • 0

I have a slightly obscure model in that Users come from Active Directory, but from then on in information arrives from the SQL db.

So, I have a UserRepository that currently allows users to search for other users from active directory – this returns a list that I bind to a grid.

I need to be able to check if each user has any Contacts (which live in the db) in order to change how the UI behaves.

How would you do this? On another page Contacts will be editable, but on the list I just need to know if there any Contacts or not. I dont see any clean way around the expense of issuing a db call to execute a stored procedure for each result to get the count, and I am getting the count rather than the list of Contacts to keep it as streamlined as possible.

I was thinking something on the lines:

/// <summary>
/// information resides in the database
/// </summary>
private int? contactsCount = null;
public int ContactsCount
{
  get
  {
    if (!contactsCount.HasValue)
      throw new ApplicationException("Error trying to access property ContactsCount before it has been initialised. The underlying repository code needs to handle the retrieval of this info.");
    return contactsCount.Value;
  }
  set { contactsCount = value; }
}

and using the UserRepository to set the value of ContactsCount after the search for each row (using a standard sql connection), but what would be nice would be to see Entity Framework in action on the actual property but I am not sure I can bind just a property to a function if the main User object is not part of the Entity Model?

  • 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-05-21T19:36:36+00:00Added an answer on May 21, 2026 at 7:36 pm

    It’s not possible directly with Entity Framework. I think this is a perfect fit for a dedicated UserRepository class, which you already have.

    As a side note, I would try to avoid having a separate db call per user, instead you can solve this with a single query, something like this [warning: untested code ahead]:

     var users = GetUsersFromActiveDirectory();
    
    
     // get the nof contacts per user fill in the contacts count for each user
     // assuming a IsContactFrom property on Contact here, which corresponds to User.UserName
     // also, assuming the number of users this is called for is 'reasonable' 
     using (db = new MyObjectContext())
     {
         var userNames = users.Select(u => u.UserName).ToList(); 
    
         var usersWithContacts = from c in db.Contacts
                                 where userNames.Contains(c.IsContactFrom)
                                 group by c.IsContactFrom into ContactsPerUser
                                 select new 
                                 {
                                    UserName = c.IsContactFrom, 
                                    NofContacts = ContactsPerUser.Count()
                                 };
    
         var dic = usersWithContacts.ToDictionary(u => u.UserName);
    
         foreach (var u in users)
         {
             u.ContactsCount = usersWithContacts[u.UserName].Count
         }
    
    
    
    
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question has been asked before ( link ) but I have slightly different
I have to interface with a slightly archaic system that doesn't use webservices. In
This is a slightly obscure question, but I'm stumped and I thought maybe somebody
I have a table that has worked correctly for many years, but recently the
I have a program which needs to behave slightly differently on Tiger than on
Currently I have two MediaWikis, one a slightly older version than the other. I
I have a list of jar files, all containing slightly different versions of the
Have you ever seen any of there error messages? -- SQL Server 2000 Could
I have a Pygame program that needs text input. The way it does this
I've taken code from the MSDN page on Matrix Filters and modified it slightly.

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.