.Net ef mvc не загружает свойство ⇐ C#

Место общения программистов C#
Anonymous
.Net ef mvc не загружает свойство

Сообщение Anonymous »

Я пытался что -то сделать в .NET EF уже некоторое время.

Код: Выделить всё

public class Route
{
[Key]
public int RouteId { get; set; }
[Display(Name = "Rope")]
public int ropeId { get; set; }
public virtual Rope rope { get; set; }
[Display(Name = "Routesetter")]
public int routeSetterId { get; set; }
public virtual RouteSetter routeSetter { get; set; }
[Display(Name = "Secundary routesetter")]
public int? secundaryRouteSetterId { get; set; }
public virtual RouteSetter secundaryRouteSetter { get; set; }
[Display(Name = "Grade")]
public int gradeId { get; set; }
public virtual ClimbingGrade grade { get; set; }
[Display (Name = "Routename")]
public string name { get; set; }
[Display(Name = "Color")]
public int colorId { get; set; }
public virtual GripColor color { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]
[Display (Name ="Date set")]
public DateTime dateSet { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]
[Display (Name ="Date removed")]
public DateTime? dateRemoved { get; set; }
[Display (Name ="Marked for removal")]
public bool markedForRemoval { get; set; }

}
< /code>
контроллер: < /p>
 public ActionResult Index()
{
var routes = db.Routes.Include(r => r.color).Include(r => r.grade).Include(r => r.rope).Include(r => r.routeSetter).Include(r => r.secundaryRouteSetter);
ViewBag.Page = "Routes";
return View(routes.ToList());
}
< /code>
Теперь свойство цвета всегда ноль. в то время как все остальные свойства загружаются. Любая помощь будет приветствоваться < /p>
 edit < /strong>
класс Gripcolor: < /p>
 public class GripColor
{
[Key]
public int GripColorId { get; set; }
[Display(Name = "Primary color")]
public string primaryColor { get; set; }
[Display(Name = "Secundary color")]
public string secundaryColor { get; set; }

public string displayName { get { return primaryColor + ' ' + secundaryColor; } }
public virtual List Routes { get; set; }
}
< /code>
Я предполагаю, что GripColors в порядке в базе данных; < /p>
ViewBag.ColorID = new SelectList(db.Colors, "GripColorId", "displayName");
Выше используется для заполнения выпадения (который работает), а Colorid хранится правильно в базе данных

Подробнее здесь: https://stackoverflow.com/questions/364 ... g-property

Вернуться в «C#»