1000+ Linq queries or database logic ... what's worse?

I asked this question in a much longer way a few days ago , and the fact that I have no answers is not surprising given the length, so I decided that I would get more.

I have to decide on how to display the user based on their assignment to a particular client. The domain object is as follows:

public class Customer
{
    public string Name { get; set; }
    public IEnumerable<Users> AssignedUsers { get; set; }
}

In the real world, I will also evaluate whether they have permissions (using bitwise comparisons on the security flags) to view this particular client, even if they are not directly assigned to it.

I am trying to adhere to the principles of domain-based rules (DDD). In addition, I use LINQ to SQL to access data. At my service level, I provide the user with a list of customers request, which now amounts to about 1000 items and is growing at about 2% per month.

If I strictly follow the logic at my service level, I will need to use Linq to execute .Where, which evaluates whether the list contains AssignedUsersa user request. This will cause a cascade of requests for each Customeras the system enumerates. I have not tested, but it seems to be ineffective.

no-logic-in-the-data, GetCustomersByUser(), EXISTS SQL . , , , , , .

, , , Linq... , ? Linq , ?

+3
6

? , .

, - DDD, , .

- , , , , , , , , .

DDD , , , , "" , .

, .

, " " . , DDD, ?

- . , , , .

+5

LINQ - , .

, , , , . MS , LINQ .

, . , , ( ):

  • . , .
  • .
  • .

3 . SQL Server? . ? .

SQL Server , , . , .

, , .

+3

AssignedUser (, Linq2SQL mark AssosiationAttribute ( - http://msdn.microsoft.com/en-us/library/system.data.linq.mapping(v=VS.90).aspx namespace, ), Linq2Sql linq SQL AssingedUser .

"" ,

from c in Customer
join u in Users on c.CustomerId equals u.AssignedToCustomerId // or other condition links user to customer
where <you condition here>
select c
+1

, Linq . , AssignedUsers . . , .

.

LinqToSql - .

int userId = CurrentUser.UserId;

IEnumerable<Customer> customerQuery =
  from c in dataContext.Customers
  where c.assignedUsers.Any(au => au.UserId = userId)
  select c;

List<Customer> result = customerQuery.ToList();
+1

proc. . , , , . , : -)

0

Source: https://habr.com/ru/post/1751478/


All Articles