編集
このようにすることもできます
List<DocumentDTO> lstDocs = objService
.SelectDocumentInfo()
.Where(l => Convert.ToInt32( (l.FileName.Split('\\'))[0] ) == docID)
.ToList();
文字列に分割機能を適用することにより
コードの 1 つの変更
List<DocumentDTO> lstDocs = objService
.SelectDocumentInfo()
.Where(l => int.Parse(l.FileName.Substring(0, l.FileName.IndexOf('\'))) == docID)
.ToList();
「=」の代わりに「==」を入れる必要があります 上記の正しいコードを確認してください
注:これは、279\Chrysanthemum.jpg のような文字列がある場合にのみ機能しますが、この 279\Chrysanthemum1.jpg のような場合にのみ失敗します
このように文字列から数値を取得して試してみてください
stringThatHaveCharacters = stringThatHaveCharacters.Trim();
Match m = Regex.Match(stringThatHaveCharacters, "\\d+");
int number = Convert.ToInt32(m.Value);
だからこのようにしてみてください
List<DocumentDTO> lstDocs = objService
.SelectDocumentInfo()
.Where(l => Convert.ToInt32( (Regex.Match(l.FileName, "\\d+")).Value) == docID)
.ToList();