2017-02-08 10 views
-1

私は、次のLINQ文を持っています。また、ファイルテーブルをインクルードし、SettingFileを持つすべてのファイルを取得したいと考えています。しかし、私は次のエラーを取得維持:ここLINQのを含めるとWhere句

Cannot implicity convert type IEnumerable(UploadedFile) to bool.

は私にUploadedFileモデルです:ここで

[Required] 
public string FileName { get; set; } 
[Required] 
public string FileExtension { get; set; } 
[Required] 
public byte[] FileContent { get; set; } 

public Guid? FormAnswerId { get; set; } 
public Guid? LicenseHolderId { get; set; } 
public Guid? CaseId { get; set; } 
public Guid? ErrandId { get; set; } 
public bool SettingFile { get; set; } 

は私の設定-モデルです:

public class Setting : ModelBase 
{ 
    public string Key { get; set; } 
    public string DisplayName { get; set; } 
    public string DisplayText { get; set; } 
    public string DisplayTab { get; set; } 
    public string Value { get; set; } 
    public string Type { get; set; } 
    public virtual ICollection<UploadedFile> Files { get; set; } 
} 

Modelbase:

public abstract class ModelBase : EntityBase 
{ 
    public DateTime? Deleted {get; set;} 
} 

質問に間違っていますか?

+1

、この '.Whereしてみてください(yは=> y.Files.Any(=> f.SettingFile F ==真))' – Magnetron

答えて

1

私はあなたが達成しようとしていることをよく理解していませんが、問題を説明することができます。

Where()節はFunc<T, bool>です。 Tのインスタンスを渡し、boolの値を返します。

この行の.Where(y => y.Files.Where(f => f.SettingFile == true))には、boolを返すIEnumerable<T>が返されます。これがエラーの原因です。 y.Files.Where(f => f.SettingFile == true)y.Files.Any(f => f.SettingFile)またはy.Files.All(f => f.SettingFile)に変更すると、エラーを解決できます。しかし、私はこれが達成しようとしているとは思わない。

編集:

_context.Settings 
     .Include(x => x.Files.Where(f => f.SettingFile == true)) 
     .Select(z => z.Deleted == null) 
     .ToList(); 

編集:あなたはSettingFile == trueその後、次の手順を実行しているすべての設定を取得しようとしているので、コメントでさらに通信した後、あなたはSettingのコレクションを望んでいたと述べました。したがって、.Select(x => z.Deleted == null)を削除するだけで、あなたは金色になるはずです。

_context.Settings 
     .Include(x => x.Files.Where(f => f.SettingFile == true)) 
     .ToList(); 

私はあなたのユースケースを知らないが、SettingFiletrueですFilesを持っていない任意のSettingsを除外するために、別のWhere条件を追加することをお勧めかもしれません。句は、IEnumerableをを返す

_context.Settings 
     .Include(x => x.Files.Where(f => f.SettingFile == true)) 
     .Where(x => x.Files.Any(f => f.SettingFile == true)) 
     .ToList(); 
+0

私の質問をお読みください。 SettingFile == trueのファイルですべての設定を取得したい。 – Bryan

+0

事はそれを試みたことです。しかし、帽子はリストの代わりにリストを返します。 – Bryan

+1

My Setting-modelはModelBaseモデルから継承します。それを提供して申し訳ありません。しかし、削除された== nullでselect節を削除すると、リストの代わりにリストが返されます Bryan