0

我不确定这是否正确,但我有一个返回 json 的 Web 服务。现在我想设置一个条件来忽略在单元格出现显示中返回值为 false 的行。大多数代码的作用非常简单,但是具有真假值的单元格是出现在表格照片中的。在 ms sql 数据库中,appearInShowcase 的类型为 ntext。

    public List<wsGalleryPhotos> GetGalleryPhotos(int collectionID)
    {
       photoDataContext dc = new photoDataContext();

        List<wsGalleryPhotos> results = new List<wsGalleryPhotos>();
        System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.GetCultureInfo("en-US");

        foreach (photo photo in dc.photos.Where(s => s.collectionID == collectionID)) 
        {
            if(photo.appearInShowcase == "true")
            {
            results.Add(new wsGalleryPhotos()
            {   

                photoID = photo.photoID,
                collectionID = Convert.ToInt32(photo.collectionID),
                name = photo.name,
                description = photo.description,
                filepath = photo.filepath,
                thumbnail = photo.thumbnail


            }); 
            }
        }

        return results;
    } 
4

1 回答 1

0

如果你想添加一个条件,你应该这样做:

public List<wsGalleryPhotos> GetGalleryPhotos(int collectionID)
    {
       photoDataContext dc = new photoDataContext();

        List<wsGalleryPhotos> results = new List<wsGalleryPhotos>();
        System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.GetCultureInfo("en-US");

        results = dc.photos.Where(s => s.collectionID == collectionID && s.appearInShowcase == "true")
                           .Select(s => new wsGalleryPhotos
                            {       
                                 photoID = s.photoID,
                                 collectionID = collectionID,
                                 name = s.name,
                                 description = s.description,
                                 filepath = s.filepath,
                                 thumbnail = s.thumbnail  
                             }).ToList();

        return results;
    } 
于 2013-07-03T06:23:59.640 回答