Retrieve a single property as a <String> from an ICollection model

I am trying to select one property [file_name] in the list from ICollection, where dr405 has many properties.

return GetDR405ById(c, id).dr405files.Select(p => p.FileName).ToList<String>();

  public class dr405files { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int FileId { get; set; } public String TangiblePropertyId { get; set; } public String FileName { get; set; } public DateTime? UploadDate { get; set; } public Byte[] FileData {get;set;} public long? FileLength { get; set; } } 

I want the SQL equivalent SELECT [Column1] FROM [Table1] as opposed to `SELECT * FROM [Table1]

+6
source share
1 answer

I think you just want to do

 return GetDR405ById(c, id).Select(p => p.FileName).ToList(); 

if GetDR405ById really does not return an object that has the dr405files property, which is a common collection of dr405files objects.

EDIT.

Note that I also removed the generic type parameter from ToList (). Filename is a string, so T will be output by the compiler.

+12
source

Source: https://habr.com/ru/post/903852/


All Articles