目标:将 SQL 视图中的数据显示到 asp.net 页面上的 ListView 有一个带有新视图的新数据库,我需要将其指向
错误:
System.Reflection.TargetInvocationException: '调用的目标已抛出异常。' 内部异常 NotSupportedException:LINQ to Entities 不支持指定的类型成员“Alternate_ID”。仅支持初始化程序、实体成员和实体导航属性。
System.InvalidOperationException: '当 DataBoundControl 启用分页时,SelectMethod 应返回 IQueryable 或应具有所有这些强制参数:int startRowIndex、int maximumRows、out int totalRowCount'
尝试过: 我查看了有关列表视图、文档、项目类型、数据绑定等的教程。我发现的其中一个问题是:LINQ to Entities 不支持指定的类型成员。仅支持初始化程序、实体成员和实体导航属性 我查看了模型、视图、检查拼写、设计器文件、pocos 等。
代码:
默认.aspx:
<asp:ListView id="lstClaims" runat="server" ItemType="Placeholder.Data.vx_EligibilitySearch" SelectMethod="lstMembers_GetData" OnItemCommand="lstMembers_ItemCommand"
ItemPlaceholderID="litPlaceHolder">
<LayoutTemplate>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th></th>
<th><asp:LinkButton id="Sort_Claim_Number" runat="server" CommandArgument="Group_Description" CommandName="Sort">Group</asp:LinkButton></th>
<th><asp:LinkButton id="Sort_Claim_Status" runat="server" CommandArgument="Group_ID" CommandName="Sort">Group ID</asp:LinkButton></th>
<th><asp:LinkButton id="Sort_Plan" runat="server" CommandArgument="Alternate_ID" CommandName="Sort">Member ID</asp:LinkButton></th>
</thead>
<asp:Literal ID="litPlaceHolder" runat="server" />
</table>
</div>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td><%# Item.Group_Description %></td>
<td><%# Item.Group_ID %></td>
<td><%# Item.Alternate_ID %></td>
</tr>
</ItemTemplate>
</asp:ListView>
注意:受保护的全局::System.Web.UI.WebControls.ListView lstClaims; 在 default.aspx.designer.cs 中
这指向 [ lstClaims.DataBind(); ] :
if (memberIDIsValid || memberIsValid)
{
ShouldSearch = true;
lstClaims.DataBind();
}
这是在方法中:lnkSearch_Click,从这里的aspx页面调用(当点击搜索按钮时):
<p><asp:LinkButton ID="lnkSearch" runat="server" OnClick="lnkSearch_Click" CssClass="btn btn-default"><i class="fa fa-search"></i> Search Members</asp:LinkButton></p>
获取数据的方法:
public IQueryable<vx_EligibilitySearch> lstMembers_GetData()
{
litNumSearchResults.Text = "";
// IQueryable<Member> members = null;
IQueryable<vx_EligibilitySearch> members = null;
try
{
if (!ShouldSearch)
return members;
panelSearchForm.Visible = false;
lnkButtonBackToSearch.Visible = true;
members = GetDataFromQuery();
public IQueryable<vx_EligibilitySearch> GetDataFromQuery()
{
// IQueryable<Member> members = null;
IQueryable<vx_EligibilitySearch> members = null;
try
{
// members = somedb.Members.AsNoTracking().AsQueryable(); //.OrderBy(a => a.Claim_Number)
members = somedb.vx_EligibilitySearch.AsNoTracking().AsQueryable(); //.OrderBy(a => a.Claim_Number)
if (!string.IsNullOrEmpty(Search_MemberID))
// members = members.Where(m => m.Subscriber_ID == Search_MemberID).AsQueryable();
members = members.Where(m => m.Alternate_ID == Search_MemberID).AsQueryable();
在部分类 vx_EligibilitySearch 我有:
public string Alternate_ID { get; set; }
更多的:
namespace Placeholder.Data
{
using System;
using System.Collections.Generic;
public partial class vx_EligibilitySearch
{
public string Subscriber_ID { get; set; }
public string Group_Description { get; set; }
public string Group_ID { get; set; }
public string Alternate_ID { get; set; }
public string Member_Name { get; set; }
public string Sex { get; set; }
public Nullable<System.DateTime> Birth_Date { get; set; }
数据库上下文:
members = somedb.vx_EligibilitySearch.AsNoTracking().AsQueryable(); //.OrderBy(a => a.Claim_Number)
转到 somedb 的定义将我带到 BasePage.cs:
protected VBADemoEntities somedb = new VBADemoEntities();
当我转到 VBADemoEntities 的定义时:
namespace Placeholder.Data
public partial class VBADemoEntities : DbContext
{
public VBADemoEntities()
: base("name=VBADemoEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<Auth> Auths { get; set; }
...........
public virtual DbSet<Member> Members { get; set; }
public virtual DbSet<vx_EligibilitySearch> vx_EligibilitySearch { get; set; }