I. Events
A recent project requires the following query to be implemented:
There are three tables: papers (Paper), periodicals (Magazine), journal Discipline Classifications (Magazinesubjectclass), and three relationships: papers and periodicals have a one-to-many relationship (one paper corresponds to one journal, one journal corresponds to multiple papers), The relationship between periodical and periodical classifications is One-to-many (a journal corresponds to multiple classifications), as shown in the figure:
The query that requires implementation is as follows:
A "Subject classification" set (a string array) is given, and the query is published in a journal of "Disciplinary Classification" belonging to this collection.
Ii. Response Events
My thinking is as follows:
Find a qualified magazine based on a disciplinary classification
Find a paper that meets the requirements according to the magazine
So I wrote the following LINQ statement:
Iqueryable<magazine> magazines = database. Magazines.asqueryable ();
if (PaperQueryInformation.MagazineQueryInformation.SubjectClass!= null && PaperQueryInformation.MagazineQueryInformation.SubjectClass.Length!= 0)
{
Magazines = database. Magazinesubjectclasses
. Where (q => paperQueryInformation.MagazineQueryInformation.SubjectClass.Contains (Q.subjectclass))
. Select (q => q.magazine)
. Distinct ();
query = Query
. Where (q => magazines. Contains (Q.magazine));
}