开发者

Left Join on Table with One-to-Many relationship

My apologies in advance for the haziness here, but I find this problem somewhat difficult to explain (although I'm sure it's a fairly common problem/solu开发者_开发问答tion). I want to execute a query selecting rows from a table joined with another table where the other table is the "many" in the one-to-many relationship. But one of my where clauses needs to check the many part for a particular condition. Here's the code with the part I don't understand filled in with pseduocode.

var query = 
    from program in db.AcademicPrograms
        where program.ProgramTitle.StartsWith(Keyword.Text) || 
              program.ProgramDeptIDName.DeptName.StartsWith(Keyword.Text) || 
              program.AcademicProgramKeywords.Contains(
                                     <A value that starts with Keyword.Text>)
        select
            new
              {
                 program.ProgramTitle,
                 program.ProgramHomePage,
                 program.ProgramCode,
                 program.ProgramType
              };


This should work for you:

program.AcademicProgramKeywords.Any(apk => apk.Field.StartsWith(Keyword.Text))

Effectively, this says:
Select AcademicPrograms where any of its AcademicProgramKeywords .Field properties starts with Keyword.Text.

I'll leave it to you to resolve .Field to the correct property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜