代码之家  ›  专栏  ›  技术社区  ›  Rigobert Song

Linq to SQL关联?

  •  0
  • Rigobert Song  · 技术社区  · 17 年前

    我有一个posts类,该post可以有一个文件,该文件可以有许多标记

    我想遍历日志中的文件并显示所有文件标记

    foreach(File f in Post.Files)
    {
        f.Tags
    }
    

    在这个前臂里我需要什么才能拿到最上面的标签?只有一个。

    我试过

    f.Tags.Select(n => n)
    

    运气不好。

    谢谢

    2 回复  |  直到 17 年前
        1
  •  1
  •   Eric Petroelje    17 年前

    要获取文件的第一个标记,请使用以下命令:

    f.Tags.First()
    

    如果每个日志有一个文件,而每个文件有多个标记,那么这样做可能更合适:

    foreach( Tag t in Post.Files.First().Tags ) {
        // Do something with t
    }
    
        2
  •  0
  •   Vasu Balakrishnan    17 年前

    posts.selectmany(ppost=>ppost.files.selectmany(pfile=>pfile.tags.select(ptag=>ptag)))