0

在 LINQ to SQL 中,我可以说 var ......Take(50); 现在我有了这个 LINQ2XML 代码:

                    XElement xml = new XElement("Materials",
                    from material in _db.MTIs
                    where material.MTName.ToString().Contains(comparer)
                    select new XElement("Material",
                              new XElement("MTID", material.MTID),
                              new XElement("MTName", material.MTName),
                              new XElement("ComputerNO", material.ComputerNO),
                              new XElement("ModelNO", material.ModelNO),
                              new XElement("Whole", material.Whole)));

我只想获得前 50 行匹配结果,我怎么能执行这样的事情?

谢谢。

4

1 回答 1

0
                XElement xml = new XElement("Materials",
                _db.MTIs.Where(material => material.MTName.ToString().Contains(comparer))
                .Take(50)
                .Select(material =>
                    new XElement("Material",
                          new XElement("MTID", material.MTID),
                          new XElement("MTName", material.MTName),
                          new XElement("ComputerNO", material.ComputerNO),
                          new XElement("ModelNO", material.ModelNO),
                          new XElement("Whole", material.Whole))));
于 2012-05-15T11:22:40.040 回答