我有一个数据表,我想在其中显示数据库中的记录,我想为此运行原始SQL查询,但不能这样做。我尝试使用dd.sqlquery,但未进入列表。该错误总是在我尝试运行查询时出现,它显示“ DbRawSqlquery不包含要列出的定义”
public ActionResult LoadData()
{
using (var Ms = new DHIFeedbackEntities2())
{
var feedbacklist = Ms.Database.SqlQuery<string>("select [FeedbackUserName],[FeedBackUserEmailID],[FeedBackComment],[Designation],[Organization],[ContactNo],[City],[FeedBackDate] from [DHIFeedback].[dbo].[FeedBack]").ToList<FeedBack>();
//var feedbacklist=Ms.FeedBacks.SqlQuery("select [FeedbackUserName],[FeedBackUserEmailID],[FeedBackComment],[Designation],[Organization],[ContactNo],[City],[FeedBackDate] from [DHIFeedback].[dbo].[FeedBack]").ToList<FeedBack>();
//var feedbacklist = Ms.FeedBacks.SqlQuery("select [FeedbackUserName],[FeedBackUserEmailID],[FeedBackComment],[Designation],[Organization],[ContactNo],[City],convert(varchar,[FeedBackDate],103) as [FeedBackDate] from [DHIFeedback].[dbo].[FeedBack]").ToList<FeedBack>();
return Json(new { data = feedbacklist }, JsonRequestBehavior.AllowGet);
}
}
<script type="text/javascript">
$(document).ready(function () {
$(document).on("click", ".opencomment", function () {
var mycomment = $(this).data('id');
$('.modal-body #commentdesc').html(mycomment);
// $('#myModal').modal('show');
});
$('#FeedbackDetails').DataTable({
"processing": true,
"ajax": {
"url": "/ViewFeedback/LoadData",
"type": "GET",
"datatype": "json"
},
"lengthMenu": [
[5, 10, 25, 50, 100, -1],
[5, 10, 25, 50, 100, "All"]
],
"autoWidth": true,
"responsive": true,
"lengthChange": true,
"ordering": true,
"fnRowCallback" : function(nRow, aData, iDisplayIndex){
var oSettings = this.fnSettings();
$("td:first", nRow).html(oSettings._iDisplayStart+iDisplayIndex +1);
return nRow;
},
"columns": [
{ "data": null, "autoWidth": true },
{ "data": "FeedbackUserName", "name": "User Name", "autoWidth": true },
{ "data": "FeedBackUserEmailID", "name": "Email ID", "autoWidth": true },
{ "data": "FeedBackComment", "name": "Comment", "autoWidth": true },
{ "data": "Designation", "name": "Designation", "autoWidth": true },
{ "data": "Organization", "name": "Organization", "autoWidth": true },
{ "data": "ContactNo", "name": "Contact No", "autoWidth": true },
{ "data": "City", "name": "City", "autoWidth": true },
{
"data": "FeedBackDate", "name": "Feedback Date", "autoWidth": true,
//'render': function (jsonDate) {
// var date = new Date(parseInt(jsonDate.substr(6)));
// var month = date.getMonth();
// return date.getDate() + "/" + month + "/" + date.getFullYear();
//}
},
],
columnDefs: [{
targets: 3,
//data:"FeedbackID",
render: function (data, type, row, meta) {
if (type === 'display' && data.length > 40) {
return '<span title="' + data + '">' + data.substr(0, 38) + '...<a href="" data-id="'+data+'" data-toggle="modal" class="opencomment" data-target="#myModal">Show More</a>';
}
else {
return data;
}
}
}],
public partial class FeedBack
{
public int FeedbackID { get; set; }
public string FeedbackUserName { get; set; }
public string FeedBackUserEmailID { get; set; }
public string FeedBackComment { get; set; }
public string Designation { get; set; }
public string Organization { get; set; }
public string ContactNo { get; set; }
public string City { get; set; }
public Nullable<System.DateTime> FeedBackDate { get; set; }
public Nullable<double> IsPublished { get; set; }
public string Reply { get; set; }
public Nullable<double> IsReplied { get; set; }
public Nullable<System.DateTime> ReplyDate { get; set; }
public string ReplyBy { get; set; }
public string Sector { get; set; }
public Nullable<int> Status { get; set; }
public int Year { get; set; }
public int January { get; set; }
public int February { get; set; }
public int March { get; set; }
public int April { get; set; }
public int May { get; set; }
public int June { get; set; }
public int July { get; set; }
public int August { get; set; }
public int September { get; set; }
public int October { get; set; }
public int November { get; set; }
public int December { get; set; }
public string Monthlyupdate { get; set; }
public DateTime Month{ get; set; }
[NotMapped]
public List<FeedBack> FeedBackCollection { get; set; }
}