Linq. Join.

S

shapper

Hello,

I have a list named Form which is a List(Of Tag) where Tag is an
object with two properties: ID and Name.

I want to define a variable named Check that:

1. Is True if all Tags in Form are found in database.Tags given each
Tag Name

2. Is False if there is at least one tag in Form that, given its name,
is not present in Database.Tags.

How can I do this?

Thanks,
Miguel
 
S

shapper

Hello,

I have a list named Form which is a List(Of Tag) where Tag is an
object with two properties: ID and Name.

I want to define a variable named Check that:

1. Is True if all Tags in Form are found in database.Tags given each
Tag Name

2. Is False if there is at least one tag in Form that, given its name,
is not present in Database.Tags.

How can I do this?

Thanks,
Miguel

I have the following:

bool verify = (from t in database.Tags
join f in Form on t.Name equals f.Name
select t).Any();

But, if I am not wrong, this checks if Any of the tags in Form exist
in database.
But I want to check if all exist.

Does anyone knows what should I do?

Thanks,
Miguel
 
S

shapper

It seems to me that you could either:

     -- reverse the join so that the result includes only those Tags in  
your Form that _don't_ appear in the database (a non-empty result  
indicates your "false" condition)
     -- compare the Count of the results to the Count of the Form; if they  
are equal, then all Tags matched, otherwise at least one didn't

Pete

I am a little bit confuse. You mean:

bool verify = (from l in list
join t in database.Tags on l.Name equals t.Name
select l).Any();

It is not working.

Am I doing something wrong?

Thanks,
Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top