Библиотека Ext.Net Форма с combobox для модели

Есть две Entity - Request и Brigade, заявки и бригады. Каждая заявка прикрепляется к бригаде. Хочу сделать UI с использованием Ext.net. Нашел пример на официальном сайте https://mvc.ext.net/#/Models/FormPanelFor/ Сделал таким образом Request.cshtml - загружается на основную страницу через Html.partial

@model GeoSystem.Db.ViewModel.FormPanelRequest
@(Html.X().FormPanelFor(m => m.request)
            .ID("RequestPanel")
            .X(10).Y(10)
                .BodyPadding(5)
                .DefaultAnchor("100%")
                .Width(300)
                .Buttons(Html.X().Button()
                    .Text("Сохранить")
                    .DirectClickUrl(Url.Action("SubmitRequest"))
                )
)

Как я понял из примера, для того, чтобы внешний ключ в UI представлялся как combobox, нужно добавить в Views/Shared/EditorTemplates представление Brigade.cshtml

@using GeoSystem.Db.ViewModel;
@model FormPanelRequest

@(
    Html.X()
    .ComboBoxFor(m => m.request.BrigadeID)
        .Items(FormPanelRequest.getBrigades().Select(d => new ListItem(d.Name, d.BrigadeID)))
        .FieldLabel("Brigade")
        .SimpleSubmit(true)
        .Listeners(l => {
            l.Select.Handler = "this.next().setValue(this.getRawValue());";
        })
)

ViewModel для этого FormPanelrequest.cs

public class FormPanelRequest
{
    public Request request { get; set; }
    private static BrigadeRepository repository = new BrigadeRepository();

    public static List<Brigade> getBrigades() {
        return repository.GetAll();
    }
}

При загрузке возникает ошибка

 System.InvalidOperationException: "The context cannot be used while the model is being created.
 This exception may be thrown if the context is used inside the OnModelCreating method or if the same 
 context instance is accessed by multiple threads concurrently.
 Note that instance members of DbContext and related classes are not guaranteed to be thread safe

Если сгенерировать вручную, без бд, то всё работает и отображается.

public static List<Brigade> getBrigades() {
            Brigade a = new Brigade();
            Brigade b = new Brigade();
            a.BrigadeID = 1;
            a.Name = "a";
            b.BrigadeID = 2;
            b.Name = "b";
            //return repository.GetAll();
            List<Brigade> l = new List<Brigade>();
            l.Add(a);
            l.Add(b);
            return l;
        }

Как подружить Entity Framework и Ext.Net?


Ответы (0 шт):