Telerik NotSupportedException 网格使用助手 class
Telerik NotSupportedException Grid using helper class
所以我正在尝试清理我的一些代码,因为我不想为我将经常重复的内容添加 30 行额外的代码。但我似乎无法让它正常工作。
我正在使用 Entity Framework 从我的数据库中获取记录,然后尝试将该 IQueryable 传递给辅助方法来完成工作并将 IQueryable 传递回初始变量。然后,该方法完成转换为 Telerik 的网格的 DataSourceResult。我认为这是导致问题的辅助方法的原因是因为我可以将所有这些都放在控制器方法中并且它工作得很好。但是当我尝试将其拆分时,它会停止工作并抛出错误。所以我一定是做错了什么。
辅助方法:
public static IQueryable<DetailedTicketModel> GetDetailedTicketModels(IQueryable<TICKET> tickets)
{
using (var ctx = new GuardianContext())
{
var detailedTickets = tickets.Select(v => new DetailedTicketModel()
{
Id = v.ID,
RequesterId = v.REQUESTER_ID,
RequesterName = v.REQUESTER_NAME,
Phone = v.PHONE,
Location = v.LOCATION,
Source = v.SOURCE,
PersonAssigned = v.PERSON_ASSIGNED,
Created = v.CREATED,
Updated = v.UPDATED,
DeptId = v.DEPT_ID,
DeptName = ctx.DEPARTMENTS.FirstOrDefault(t => t.ID == v.DEPT_ID).NAME,
TopicId = v.TOPIC_ID,
TopicName = ctx.TICKET_TOPICS.FirstOrDefault(t => t.ID == v.TOPIC_ID).NAME,
StatusId = v.STATUS_ID,
StatusName = ctx.TICKET_STATUSES.FirstOrDefault(t => t.ID == v.STATUS_ID).NAME,
PriorityId = v.PRIORITY_ID,
PriorityName = ctx.TICKET_PRIORITIES.FirstOrDefault(t => t.ID == v.PRIORITY_ID).NAME,
PriorityHexColor = ctx.TICKET_PRIORITIES.FirstOrDefault(t => t.ID == v.PRIORITY_ID).HEX_COLOR,
TicketEvents = ctx.TICKET_EVENTS.Where(t => t.TICKET_ID == v.ID).OrderBy(t => t.CREATED),
RequestBody =
ctx.TICKET_EVENTS.OrderBy(t => t.CREATED).FirstOrDefault(t => t.TICKET_ID == v.ID).BODY,
RequestFormat =
ctx.TICKET_EVENTS.OrderBy(t => t.CREATED).FirstOrDefault(t => t.TICKET_ID == v.ID).FORMAT,
});
return detailedTickets;
}
}
调用方法的控制器:
public ActionResult UnassignedTickets_Read([DataSourceRequest]DataSourceRequest request)
{
Debug.WriteLine("UnassignedTickets_Read");
using (var ctx = new GuardianContext())
{
var detailedTickets =
TicketHelper.GetDetailedTicketModels(ctx.TICKETS.Where(v => v.PERSON_ASSIGNED == null));
//PROBLEM HAPPENS AT THE NEXT STATEMENT
var result = detailedTickets.ToDataSourceResult(request, ticket => new
{
ticket.Id,
ticket.RequesterId,
ticket.RequesterName,
ticket.Created,
ticket.RequestBody,
ticket.RequestFormat
});
return Json(result);
}
}
这是错误发生时的输出
A first chance exception of type 'System.NotSupportedException' occurred in EntityFramework.dll
A first chance exception of type 'System.NotSupportedException' occurred in EntityFramework.dll
A first chance exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll
A first chance exception of type 'System.NotSupportedException' occurred in System.Web.Mvc.dll
A first chance exception of type 'System.NotSupportedException' occurred in System.Web.Mvc.dll
如果有帮助的话,这里是剃须刀代码
@if (ViewBag.UnassignedTicketsAvailable)
{
<h3 class="page-header">Unassigned Tickets</h3>
@(Html.Kendo().Grid<Guardian.ViewModels.DetailedTicketModel>()
.Name("unassigned_grid")
.Columns(columns =>
{
columns.Bound(ticket => ticket.Id).Visible(false);
columns.Bound(ticket => ticket.RequesterId);
columns.Bound(ticket => ticket.RequesterName);
columns.Bound(ticket => ticket.Created);
})
.DataSource(dataSource => dataSource.Ajax().Read(read => read.Action("UnassignedTickets_Read", "Ticket"))
)
.ClientDetailTemplateId("client-template")
.Sortable()
.Pageable()
.Filterable()
)
}
<script id="client-template" type="text/kendo-tmpl">
@(Html.Raw("<div style\"padding: 0.4em;\">#=RequestBody#</div>"))
</script>
<script>
function dataBound() {
this.expandRow(this.tbody.find("tr.k-master-row").first());
}
</script>
我的问题是我需要在我的助手 class 中进行预加载。所以我的 return 在哪里我应该有...
return detailedTickets.ToList();
希望这对某人有所帮助。
所以我正在尝试清理我的一些代码,因为我不想为我将经常重复的内容添加 30 行额外的代码。但我似乎无法让它正常工作。
我正在使用 Entity Framework 从我的数据库中获取记录,然后尝试将该 IQueryable 传递给辅助方法来完成工作并将 IQueryable 传递回初始变量。然后,该方法完成转换为 Telerik 的网格的 DataSourceResult。我认为这是导致问题的辅助方法的原因是因为我可以将所有这些都放在控制器方法中并且它工作得很好。但是当我尝试将其拆分时,它会停止工作并抛出错误。所以我一定是做错了什么。
辅助方法:
public static IQueryable<DetailedTicketModel> GetDetailedTicketModels(IQueryable<TICKET> tickets)
{
using (var ctx = new GuardianContext())
{
var detailedTickets = tickets.Select(v => new DetailedTicketModel()
{
Id = v.ID,
RequesterId = v.REQUESTER_ID,
RequesterName = v.REQUESTER_NAME,
Phone = v.PHONE,
Location = v.LOCATION,
Source = v.SOURCE,
PersonAssigned = v.PERSON_ASSIGNED,
Created = v.CREATED,
Updated = v.UPDATED,
DeptId = v.DEPT_ID,
DeptName = ctx.DEPARTMENTS.FirstOrDefault(t => t.ID == v.DEPT_ID).NAME,
TopicId = v.TOPIC_ID,
TopicName = ctx.TICKET_TOPICS.FirstOrDefault(t => t.ID == v.TOPIC_ID).NAME,
StatusId = v.STATUS_ID,
StatusName = ctx.TICKET_STATUSES.FirstOrDefault(t => t.ID == v.STATUS_ID).NAME,
PriorityId = v.PRIORITY_ID,
PriorityName = ctx.TICKET_PRIORITIES.FirstOrDefault(t => t.ID == v.PRIORITY_ID).NAME,
PriorityHexColor = ctx.TICKET_PRIORITIES.FirstOrDefault(t => t.ID == v.PRIORITY_ID).HEX_COLOR,
TicketEvents = ctx.TICKET_EVENTS.Where(t => t.TICKET_ID == v.ID).OrderBy(t => t.CREATED),
RequestBody =
ctx.TICKET_EVENTS.OrderBy(t => t.CREATED).FirstOrDefault(t => t.TICKET_ID == v.ID).BODY,
RequestFormat =
ctx.TICKET_EVENTS.OrderBy(t => t.CREATED).FirstOrDefault(t => t.TICKET_ID == v.ID).FORMAT,
});
return detailedTickets;
}
}
调用方法的控制器:
public ActionResult UnassignedTickets_Read([DataSourceRequest]DataSourceRequest request)
{
Debug.WriteLine("UnassignedTickets_Read");
using (var ctx = new GuardianContext())
{
var detailedTickets =
TicketHelper.GetDetailedTicketModels(ctx.TICKETS.Where(v => v.PERSON_ASSIGNED == null));
//PROBLEM HAPPENS AT THE NEXT STATEMENT
var result = detailedTickets.ToDataSourceResult(request, ticket => new
{
ticket.Id,
ticket.RequesterId,
ticket.RequesterName,
ticket.Created,
ticket.RequestBody,
ticket.RequestFormat
});
return Json(result);
}
}
这是错误发生时的输出
A first chance exception of type 'System.NotSupportedException' occurred in EntityFramework.dll
A first chance exception of type 'System.NotSupportedException' occurred in EntityFramework.dll
A first chance exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll
A first chance exception of type 'System.NotSupportedException' occurred in System.Web.Mvc.dll
A first chance exception of type 'System.NotSupportedException' occurred in System.Web.Mvc.dll
如果有帮助的话,这里是剃须刀代码
@if (ViewBag.UnassignedTicketsAvailable)
{
<h3 class="page-header">Unassigned Tickets</h3>
@(Html.Kendo().Grid<Guardian.ViewModels.DetailedTicketModel>()
.Name("unassigned_grid")
.Columns(columns =>
{
columns.Bound(ticket => ticket.Id).Visible(false);
columns.Bound(ticket => ticket.RequesterId);
columns.Bound(ticket => ticket.RequesterName);
columns.Bound(ticket => ticket.Created);
})
.DataSource(dataSource => dataSource.Ajax().Read(read => read.Action("UnassignedTickets_Read", "Ticket"))
)
.ClientDetailTemplateId("client-template")
.Sortable()
.Pageable()
.Filterable()
)
}
<script id="client-template" type="text/kendo-tmpl">
@(Html.Raw("<div style\"padding: 0.4em;\">#=RequestBody#</div>"))
</script>
<script>
function dataBound() {
this.expandRow(this.tbody.find("tr.k-master-row").first());
}
</script>
我的问题是我需要在我的助手 class 中进行预加载。所以我的 return 在哪里我应该有...
return detailedTickets.ToList();
希望这对某人有所帮助。