user2740190
user2740190

Reputation:

Looking for a value in a column of many tables

I have a method returning Boolean in my repository. Its job is to look for the value that is passed in and see if ANY of the tables in their personnel_key column have that value. So for example:

public bool IsPersonnelKeyDuplicate(string per_k)
{
   var result = (from f in this.Context.Personnel where f.personnel_key  == per_k select f).Any();
   return result;
}

So that is how I am looking in one of those tables. But I have like 20 more tables to add to this method. What is a good way of doing this? Do you suggest I write a big "OR" of all these ".Any()" statements?

Thanks.

Upvotes: 0

Views: 38

Answers (1)

BobakDotA
BobakDotA

Reputation: 323

If LINQ to Entities like you posted is all you can use: Then yes. That is the way to go. But if will be extremely inefficient as you will be querying database for N times. See if you can use normal ADO and SQL commands, then you will only query the database one time and not N times.

Upvotes: 1

Related Questions