Как мне прочитать поле ImgUrl? в MVC
Realty.cs
public class Realty
{
public List<string> ImgUrl { get; set; }
public int Id { get; set; }
public string Type { get; set; }
public int? NumberRoom { get; set; }
public string Address { get; set; }
public double Square { get; set; }
public int? Floor { get; set; } //этаж
public int? Floors { get; set; } //всего этажей
public string Status { get; set; }
public int CityId { get; set; }
public int OwnerId { get; set; }
public int Price { get; set; }
public string Description { get; set; }
public int? RealtorId { get; set; }
}
инициализация бд
...
List<string> urls = new List<string>();
urls.Add(imgUrl);
urls.Add(imgUrl);
db.Realties.Add(new Realty { ImgUrl = urls, Floors = 10, Type = Types.APARTMENT, NumberRoom = 1, Square = 34, Floor = 2, Status = Statuses.RENT_OUT, CityId = 1, Address = "Северная, дом 20", OwnerId = 3, Price = 12000, Description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum rhoncus iaculis facilisis. Ut mollis libero magna, ut dapibus mi eleifend sit amet. Nam lacinia sodales tellus, vel tristique nisi auctor quis. Nulla congue mauris ac accumsan laoreet. Proin ac dui in ligula commodo facilisis. Integer pretium velit sollicitudin luctus interdum. Nam ac dui at risus posuere fringilla. Donec ac lacus ligula. Duis blandit lacus et leo euismod gravida. Aliquam leo enim, fermentum vitae felis quis, rutrum fringilla nisl. Aliquam erat volutpat. Nullam mattis magna magna, et fermentum odio imperdiet sed." });
db.Realties.Add(new Realty { ImgUrl = urls, Floors = 10, Type = Types.APARTMENT, NumberRoom = 3, Square = 70, Floor = 5, Status = Statuses.RENT_OUT, CityId = 1, Address = "Кондарева Ул., дом 2", OwnerId = 3, Price = 30000, Description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum rhoncus iaculis facilisis. Ut mollis libero magna, ut dapibus mi eleifend sit amet. Nam lacinia sodales tellus, vel tristique nisi auctor quis. Nulla congue mauris ac accumsan laoreet. Proin ac dui in ligula commodo facilisis. Integer pretium velit sollicitudin luctus interdum. Nam ac dui at risus posuere fringilla. Donec ac lacus ligula. Duis blandit lacus et leo euismod gravida. Aliquam leo enim, fermentum vitae felis quis, rutrum fringilla nisl. Aliquam erat volutpat. Nullam mattis magna magna, et fermentum odio imperdiet sed." });
db.Realties.Add(new Realty { ImgUrl = urls, Floors = 12, Type = Types.APARTMENT, NumberRoom = 2, Square = 55, Floor = 7, Status = Statuses.RENT_OUT, CityId = 1, Address = "Маяковского Ул., дом 14", OwnerId = 1, Price = 3000000, Description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum rhoncus iaculis facilisis. Ut mollis libero magna, ut dapibus mi eleifend sit amet. Nam lacinia sodales tellus, vel tristique nisi auctor quis. Nulla congue mauris ac accumsan laoreet. Proin ac dui in ligula commodo facilisis. Integer pretium velit sollicitudin luctus interdum. Nam ac dui at risus posuere fringilla. Donec ac lacus ligula. Duis blandit lacus et leo euismod gravida. Aliquam leo enim, fermentum vitae felis quis, rutrum fringilla nisl. Aliquam erat volutpat. Nullam mattis magna magna, et fermentum odio imperdiet sed." });
db.Realties.Add(new Realty { ImgUrl = urls, Floors = 2, Type = Types.HOUSE, NumberRoom = 5, Square = 102, Status = Statuses.FOR_RENT_DAILY, CityId = 1, Address = "Маяковского Ул., дом 14", OwnerId = 2, Price = 50000, Description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum rhoncus iaculis facilisis. Ut mollis libero magna, ut dapibus mi eleifend sit amet. Nam lacinia sodales tellus, vel tristique nisi auctor quis. Nulla congue mauris ac accumsan laoreet. Proin ac dui in ligula commodo facilisis. Integer pretium velit sollicitudin luctus interdum. Nam ac dui at risus posuere fringilla. Donec ac lacus ligula. Duis blandit lacus et leo euismod gravida. Aliquam leo enim, fermentum vitae felis quis, rutrum fringilla nisl. Aliquam erat volutpat. Nullam mattis magna magna, et fermentum odio imperdiet sed." });
db.Realties.Add(new Realty { ImgUrl = urls, Floors = 1, Type = Types.WAREHOUSE, Square = 100, Floor = 1, Status = Statuses.SALE, CityId = 1, Address = "102 Квартал, дом 56", OwnerId = 1, Price = 30000, Description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum rhoncus iaculis facilisis. Ut mollis libero magna, ut dapibus mi eleifend sit amet. Nam lacinia sodales tellus, vel tristique nisi auctor quis. Nulla congue mauris ac accumsan laoreet. Proin ac dui in ligula commodo facilisis. Integer pretium velit sollicitudin luctus interdum. Nam ac dui at risus posuere fringilla. Donec ac lacus ligula. Duis blandit lacus et leo euismod gravida. Aliquam leo enim, fermentum vitae felis quis, rutrum fringilla nisl. Aliquam erat volutpat. Nullam mattis magna magna, et fermentum odio imperdiet sed." });
db.Realties.Add(new Realty { ImgUrl = urls, Floors = 10, Type = Types.ROOM, Square = 15, Floor = 10, Status = Statuses.RENT_OUT, CityId = 1, Address = "236 Квартал, дом 20", OwnerId = 1, Price = 5000, Description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum rhoncus iaculis facilisis. Ut mollis libero magna, ut dapibus mi eleifend sit amet. Nam lacinia sodales tellus, vel tristique nisi auctor quis. Nulla congue mauris ac accumsan laoreet. Proin ac dui in ligula commodo facilisis. Integer pretium velit sollicitudin luctus interdum. Nam ac dui at risus posuere fringilla. Donec ac lacus ligula. Duis blandit lacus et leo euismod gravida. Aliquam leo enim, fermentum vitae felis quis, rutrum fringilla nisl. Aliquam erat volutpat. Nullam mattis magna magna, et fermentum odio imperdiet sed." });
db.Realties.Add(new Realty { ImgUrl = urls, Id = 7, Status = Statuses.LEASED, Type = Types.APARTMENT, NumberRoom = 2, Floor = 2, Floors = 10, CityId = 1, Address = "Каштановая Ул., дом 15, кв. 32", OwnerId = 3, Price = 1200000, RealtorId = 3});
db.Realties.Add(new Realty { ImgUrl = urls, Id = 8, Status = Statuses.LEASED, Type = Types.BUILDING, Floors = 10, CityId = 2, Address = "Учительская Ул., дом 48", OwnerId = 4, Price = 3000000, RealtorId = 3, });
db.Realties.Add(new Realty { ImgUrl = urls, Id = 9, Status = Statuses.LEASED, Type = Types.GARAGE, Floors = 1, CityId = 3, Address = "Океанский Проспект, дом 10", OwnerId = 5, Price = 3000000, RealtorId = 3, });
db.Realties.Add(new Realty { ImgUrl = urls, Id = 10, Status = Statuses.LEASED, Type = Types.ROOM, Floor = 2, Floors = 10, CityId = 3, Address = "Океанский Проспект, дом 10, кв. 40", OwnerId = 6, Price = 5000000, RealtorId=1 });
db.Realties.Add(new Realty { ImgUrl = urls, Id = 11, Status = Statuses.LEASED, Type = Types.BED, Floor = 5, Floors = 10, CityId = 1, Address = "Бабушкиной Н. Ул., дом 16, кв. 147", OwnerId = 1, Price = 3200000, RealtorId=2 });
db.Realties.Add(new Realty { ImgUrl = urls, Id = 12, Status = Statuses.LEASED, Type = Types.HOUSE, NumberRoom = 5, Floors = 3, CityId = 2, Address = "50-Й Мк-Н, дом 29", OwnerId = 2, Price = 5250000, RealtorId = 1 });
...
получение данных бд
IList<Realty> realties = db.Realties.Where(r => r.Status == status).ToList();
realties.ImgUrl оказывается null, хотя при инициализации все нормально
если написать так
object p = db.Entry(db.Realties).Collection(r => r.ImgUrl);
то появляется ошибка CS1061
upd: получается ImgUrl видно только при инициализации, а потом почему-то перестает существовать