C# System.Data.Entity.Core.Entity命令执行异常
获取列表时显示以下未处理的用户异常 System.Data.Entity.Core.EntityCommandExecutionException:'数据读取器与指定的'EE_PlacementCellModel.PlacedCandidateList'不兼容。“DriveDate”类型的成员在数据读取器中没有同名的对应列 异常显示在最后一个返回代码中: Placement.Context.csC# System.Data.Entity.Core.Entity命令执行异常,c#,visual-studio,exception,model-view-controller,datareader,C#,Visual Studio,Exception,Model View Controller,Datareader,获取列表时显示以下未处理的用户异常 System.Data.Entity.Core.EntityCommandExecutionException:'数据读取器与指定的'EE_PlacementCellModel.PlacedCandidateList'不兼容。“DriveDate”类型的成员在数据读取器中没有同名的对应列 异常显示在最后一个返回代码中: Placement.Context.cs public virtual ObjectResult<PlacedCandidateList
public virtual ObjectResult<PlacedCandidateList> PlacedCandidateList(Nullable<int> mstID, Nullable<int> cmpID)
{
var mstIDParameter = mstID.HasValue ?
new ObjectParameter("MstID", mstID) :
new ObjectParameter("MstID", typeof(int));
var cmpIDParameter = cmpID.HasValue ?
new ObjectParameter("CmpID", cmpID) :
new ObjectParameter("CmpID", typeof(int));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<PlacedCandidateList>("PlacedCandidateList", mstIDParameter, cmpIDParameter);
}
公共虚拟对象结果PlacedCandidateList(可为空的mstID、可为空的cmpID)
{
var mstIDParameter=mstID.HasValue?
新的ObjectParameter(“MstID”,MstID):
新的ObjectParameter(“MstID”,typeof(int));
var cmpID参数=cmpID.HasValue?
新对象参数(“CmpID”,CmpID):
新的ObjectParameter(“CmpID”,typeof(int));
返回((IObjectContextAdapter)this.ObjectContext.ExecuteFunction(“PlacedCandidateList”,mstIDParameter,cmpIDParameter);
}
其他相关代码如下所示:
ReportController.cs
public virtual ObjectResult<PlacedCandidateList> PlacedCandidateList(Nullable<int> mstID, Nullable<int> cmpID)
{
var mstIDParameter = mstID.HasValue ?
new ObjectParameter("MstID", mstID) :
new ObjectParameter("MstID", typeof(int));
var cmpIDParameter = cmpID.HasValue ?
new ObjectParameter("CmpID", cmpID) :
new ObjectParameter("CmpID", typeof(int));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<PlacedCandidateList>("PlacedCandidateList", mstIDParameter, cmpIDParameter);
}
public ActionResult PlacedCandidateList(字符串MstID,字符串CmpID)
{
int-driveID=0;
int companyID=0;
如果(MstID!=“”)
driveID=Convert.ToInt32(MstID);
如果(CmpID!=“”)
companyID=转换为32(CmpID);
ViewBag.Status=Db.Status.ToList();
var List=Db.PlacedCandidateList(driveID,companyID);
返回Json(List.ToList(),JsonRequestBehavior.AllowGet);
}
公共行动结果PlacedCandidate()
{
ViewBag.Drive=Db.DriveMasters.Where(a=>a.Isdeleted==false).ToList();
ViewBag.Company=Db.companys.Where(a=>a.Isdeleted==false).ToList();
返回视图();
}
[HttpPost]
公共行动结果地点日期(候选名单候选人)
{
ViewBag.Drive=Db.DriveMasters.Where(a=>a.Isdeleted==false).ToList();
ViewBag.Company=Db.companys.Where(a=>a.Isdeleted==false).ToList();
if(candidate.CompanyID==null)
candidate.CompanyID=0;
if(candidate.DriveMasterID==null)
候选。DriveMasterID=0;
List CSL=新列表();
CSL=Db.PlacedCandidateList(candidate.DriveMasterID,candidate.CompanyID).ToList();
WebGrid grid=新的WebGrid(来源:CSL,canPage:false,canSort:false);
字符串gridhtml=grid.GetHtml(
列:grid.columns(
网格栏(“序列号”、“序列号”),
grid.Column(“学生名”、“学生名”),
grid.Column(“驱动器名”、“驱动器名”),
//网格栏(“驱动日期”、“驱动日期”),
网格栏(“公司名称”、“公司名称”),
网格栏(“位置名称”、“位置名称”)
)).ToString();
string exportdata=string.Format(“{0}{1}”,“表{border collapse:collapse;width:100%;border:1px solid#ddd;}th,td{text align:left;padding:8px;width:100px;border bottom:1px solid#ddd;}tr n子项(偶数){background color:#f2f2}th{背景色:#4CAF50;color:white;}”,gridhtml);
var bytes=System.Text.Encoding.UTF8.GetBytes(exportdata);
使用(var输入=新内存流(字节))
{
var输出=新的MemoryStream();
var document=新的iTextSharp.text.document(PageSize.A4,50,50,50);
var writer=PdfWriter.GetInstance(文档,输出);
writer.CloseStream=false;
document.Open();
var xmlworker=iTextSharp.tool.xml.XMLWorkerHelper.GetInstance();
ParseXHtml(writer、文档、输入、System.Text.Encoding.UTF8);
文件名称(“被提名候选人”);
document.AddCreationDate();
document.Close();
输出位置=0;
返回新文件streamresult(输出,“application/pdf”);
}
}
PlacedCandidateList.cs
public virtual ObjectResult<PlacedCandidateList> PlacedCandidateList(Nullable<int> mstID, Nullable<int> cmpID)
{
var mstIDParameter = mstID.HasValue ?
new ObjectParameter("MstID", mstID) :
new ObjectParameter("MstID", typeof(int));
var cmpIDParameter = cmpID.HasValue ?
new ObjectParameter("CmpID", cmpID) :
new ObjectParameter("CmpID", typeof(int));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<PlacedCandidateList>("PlacedCandidateList", mstIDParameter, cmpIDParameter);
}
/------------------------------------------------------------------------------
//
被提名的候选人
报告
被安置的候选人
安置驱动器
@Html.DropDownListFor(model=>model.DriveMasterID,新选择列表(ViewBag.Drive,“DriveMasterID”,“DriveName”),“选择驱动器”,新{@class=“form control”,@Onchange=“GetVariables();”})
单位
@Html.DropDownListFor(model=>model.CompanyID,new SelectList(ViewBag.Company,“CompanyID”,“CompanyName”),“Select Company”,new{@class=“form control”,@Onchange=“GetVariables();”})
@model PlacementCell.Models.CandidateList
@{
ViewBag.Title = "Placed Candidate";
}
@using (Html.BeginForm("PlacedCandidate", "Report", FormMethod.Post, new { enctype = "multipart/form-data", name = "candidate", id = "candidate" }))
{
<div class="callout bg-gray-light">
<div class="row">
<div class="col-xs-2 col-md-1"><a href="#" onclick="document.getElementById('candidate').submit();"><div class="btn btn-app btn-twitter"><i class="glyphicon glyphicon-print"></i>Print</div></a></div>
</div>
</div>
<section class="content-header">
<h1>
Placed Candidates
<small>Report</small>
</h1>
<ol class="breadcrumb">
<li><a href="#"><i class="fa fa-list-alt"></i> Report</a></li>
<li class="active"><i class="fa fa-circle-o"></i> Placed Candidates</li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<div class="box">
<div class="box-body">
<br />
<div class="row">
<div class="col-xs-12 col-md-6">
<div class="form-horizontal">
<div class="form-group">
<div class="col-md-6"> Placement Drive</div>
<div class="col-md-6">
@Html.DropDownListFor(model => model.DriveMasterID, new SelectList(ViewBag.Drive, "DriveMasterID", "DriveName"), "Select Drive", new { @class = "form-control", @Onchange = " GetVariables();" })
</div>
</div>
<div class="form-group">
<div class="col-md-6">Company</div>
<div class="col-md-6">
@Html.DropDownListFor(model => model.CompanyID, new SelectList(ViewBag.Company, "CompanyID", "CompanyName"), "Select Company", new { @class = "form-control", @Onchange = " GetVariables();" })
</div>
</div>
<div class="form-group">
<div class="col-md-6"></div>
<div class="col-md-6">
<a href="#" onclick="GetList();" class="btn btn-primary">Find</a>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<table class="table table-bordered table-hover dataTable">
<thead>
<tr>
<th>
<input type="checkbox" class="checkbox" />All
</th>
<th>
Sl.
</th>
<th>
Company Name
</th>
<th>
Drive Name
</th>
<th>
Drive Date
</th>
<th>
Position Name
</th>
<th>
Student Name
</th>
<th>
</th>
</tr>
</thead>
<tbody id="drive">
<tr>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
}
@section scripts
{
<script type="text/javascript">
function GetList() {
var MstID = document.getElementById("DriveMasterID").value;
var CmpID = document.getElementById("CompanyID").value;
//alert(MstID);
$.ajax({
url: '/Report/PlacedCandidateList',
type: "GET",
data: { MstID: MstID, CmpID: CmpID },
dataType: "JSON",
success: function (List) {
//alert("ffffg");
$("#drive").html(""); // clear before appending new list
//alert("ff");
var k = 10;
var j = 1;
$.each(List, function (i, vari) {
var Qun = "arr" + k;
var ErrorQun = "arre" + k;
var chbbx = '<tr id="checkboxes"><td><input type="checkbox" name="CandidatesListID" id=' + k + ' class="checkbox" value=" ' + vari.CandidatesListID + '" checked="checked" disabled="disabled" /></td><td> ' + j + ' </td><td> ' + vari.CompanyName + ' </td><td> ' + vari.DriveName + ' </td><td> ' + vari.DriveDate + '</td><td> ' + vari.PositionName + ' </td><td> ' + vari.StudentName + ' </td><td> ' + vari.Status + '</td></tr>';
$("#drive").append(
$(chbbx));
k++;
j++;
//alert(place.Place1);
}
);
},
error: function (List) {
alert("No Data Found");
$("#drive").html("");
}
});
}
</script>
}