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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:31:15+00:00 2026-05-23T16:31:15+00:00

i separated my application into a DAL, BL, UI. I used entity framework code

  • 0

i separated my application into a DAL, BL, UI.

I used entity framework code first throw repositories to access the sql database.

public class Person{
   ...
}    
public class PersonRepository{

   Create(...){...}
   Update(...){...}
   Delete(...){...}
   GetById(...){...}
   Query(...){...}

   ...

Now the thing is the BL i’m working on a method to get all the Persons who are leaving near an adress

 public GetPersonsNear(string Address){
 ...
 }
 private bool AddressesAreClose(string address1, string address2)
 {
 ...
 } 

the thing is linq does’nt let me use my method (in a query passed in the “Query” method of the repository)

 ...
 PersonRepository personRepository = new PersonRepository();
 var person = repository.Query(p => AddressAreClose(adress,p.Adress); 
 ...

therefor i needed to get All the elements of the table in a list using a simple foreach loop to make the tests and keeping only the relevant ones

  ...
 PersonRepository personRepository = new PersonRepository();
 var persons = personRepository.GetAll;
 foreach(person in persons)
 {
    if(AdressAreClose(adress,person.adress))
    ...
  }

for now i populated the database with only a few elements to test it, but i’m not sure it would work very well with the far more greater number it will contain later specially with all the test i’m planing to add

isn’t there a more clever way to do this ??? I’m open to anything

  • 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-23T16:31:16+00:00Added an answer on May 23, 2026 at 4:31 pm

    Well first of all, you should use generics in your repository, even if it’s constrained to Person. This way you can build pipes/filters off your queries to clean up your LINQ queries and facilitate reuse.

    Of course, without seeing the full signature/implementation of your Query method, it’s hard to tell. But either way, you need to return IEnumerable<Person> or IQueryable<Person> to make the following work.

    So, you could turn AddressesAreClose into a pipe/filter, like this:

    public static bool WhereAddressesAreClose(this IQueryable<Person> source, string address)
    {
       return source.Where(/* your conditions */);
    }
    

    Then you can use it in your LINQ query:

    var person = repository
       .Query() // Should be IQueryable<Person>
       .WhereAddressAreClose(adress);
       .ToList();
    

    Depending on the size of your data and whether or not your implementing caching, you should limit the results on the server (database), not post-query with a foreach loop.

    If the performance isn’t great, consider adding indexes, using compiled queries or moving to a stored procedure.

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

Sidebar

Related Questions

What should be the general guidelines/gotchas for dividing application code (App_Code) into separate files?
I have to deploy my ASP.NET application into two seperated IIS servers. My application
In our web applications, we seperate our Data Access Layers out into their own
I am involved in development of a tiered application that uses LINQ2SQL separated from
I have a rails application where each user has a separate database. (taking Joel
I am trying to achieve adding the animated gifs into my application. 1- I
I've run into an organization problem with windows application form that I need some
I have to use many different images into my windows phone application. Although I
I'm currently developing an application that is comprised of five separate executables that communicate
I'm building a PHP application using the data mapper pattern to separate my DB

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.