简体   繁体   English

我看不到使用ToList(); 或在此select语句中使用(6)个项目

[英]I cant seen to use ToList(); or take(6) items on this select statement

I cant seen to use ToList(); 我看不到使用ToList(); or take(6) items on this select statement. 或在此select语句中使用(6)个项目。 I need to select only 6. this is what i have witch works but displays 1 only on the 6 iterations of the repeater. 我只需要选择6。这是我在巫婆身上所做的工作,但是仅在转发器的6次迭代中显示1。

    public string GetImage(string pId)
    {
        Compras context = new Compras();
        Product pr = context.Products.FirstOrDefault();
        if (pr != null && pr.Picture != null && pr.Picture.Count() > 0)
        {
            return "data:image/jpg;base64," + Convert.ToBase64String((pr.Picture));
        }
        return "data:image/jpg;base64," + Convert.ToBase64String(File.ReadAllBytes(Server.MapPath("~/") + "white.jpg"));
    }

I wish i could use as on this next: 我希望我可以像下面这样使用:

        var context = new Compras();
        var prouctQ = from p in context.Products.Take(6) select new { p.ProductName, p.Picture }; //with projections
        var Products = prouctQ.ToList();
        if (Products.Count > 0)

请确保您在代码文件的顶部具有“ using System.Linq”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM