Building a Kendo UI grid dynamically - asp.net-mvc

I am having challenge making my Kendo Grid Title from an array columnName as shown in the code below. columnName is an array that i want to use as my column/field name.
#(Html.Kendo()
.Grid<rtxVending.Web.Models.ProductDetails>()
.Name("ProductDetailGrid").ClientDetailTemplateId("")
.HtmlAttributes(new { #style = "align:center; font-size:9px;" })
.Columns(columns =>
{
var colums = rtxVending.Web.Repositories.SessionRepository.GetSessionObject<IList<rtxVending.Web.Models.
ProductCategoryTags>>(ApplicationConstants.sesProductsHeaderCategoryTags);
if (colums != null && colums.Count > 0)
{
**//columnName is an array that i want to use as my column/field name**
var columnName = colums.Select(a => a.ValueX).ToArray();
foreach (var column in columnName)
{
columns.Bound(column.ToString());
}
}
else
{
columns.Bound(o => o.Amount).Width(100);
columns.Bound(o => o.Value).Width(100);
columns.Bound(o => o.Value1).Width(100);
columns.Bound(o => o.Value2).Width(100);
columns.Bound(o => o.Value3).Width(100);
columns.Bound(o => o.Value4).Width(100);
columns.Bound(o => o.Value5).Width(100);
columns.Bound(o => o.Value6).Width(100);
columns.Bound(o => o.Value7).Width(100);
columns.Bound(o => o.Value8).Width(100);
columns.Bound(o => o.Value9).Width(100);
columns.Bound(o => o.Value10).Width(100);
}
})
.Pageable(pager => pager.Refresh(true))
.Sortable()
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetProductDetailsGrid", "Products"))
.Events(events => events.Error("error_handler"))
)
)

Thank you Prof. Pickle for your response.
This is what I have done. The method where the grid data is read from is as below.
public ActionResult GetProductDetailsGrid([DataSourceRequest] DataSourceRequest request)
{
try
{
List<ProductDetails> productDetails = null;
//IEnumerable<ProductDetails> productDetails = null;
if (SessionRepository.VerifySessionExists(ApplicationConstants.sesProductDetails))
{
productDetails = SessionRepository.GetSessionObject<List<ProductDetails>>(ApplicationConstants.sesProductDetails).ToList(); //.AsEnumerable();
//Return converted list<T> as DataTable
var dataTable = ToDataTable<ProductDetails>(productDetails);
if (dataTable != null)
{
var dataColumnCollection = dataTable.Columns;
SessionRepository.CacheSession<DataColumnCollection>(ApplicationConstants.sesAcquireStockDataColumnCollection, dataColumnCollection);
}
return Json(dataTable.ToDataSourceResult(request));
}
}
catch (Exception ex)
{
ModelState.AddModelError("", ex.Message);
return Json(ModelState.ToDataSourceResult());
}
return Json(ModelState.ToDataSourceResult(request));
}
my model is
public class ProductDetails
{
[Key,ScaffoldColumn(false)]
public long ProductDetailId { get; set; }
public int ProductHeaderId { get; set; }
public double Amount { get; set; }
public string Value { get; set; }
public string Value1 { get; set; }
public string Value2 { get; set; }
public string Value3 { get; set; }
public string Value4 { get; set; }
public string Value5 { get; set; }
public string Value6 { get; set; }
public string Value7 { get; set; }
public string Value8 { get; set; }
public string Value9 { get; set; }
public string Value10 { get; set; }
public string Value1DisplayName {get; set;}
public bool Valid { get; set; }
}
Before the view comes up i pass in data to the grid if my session is not null else it passes nothing to the view as shown below:
public ActionResult AcquireStock()
{
//TODO uncomment the Session Below
//SessionRepository.RemoveSession(ApplicationConstants.sesProductDetails);
var productHeader = new ProductHeaders();
if (SessionRepository.VerifySessionExists(ApplicationConstants.sesProductDetails))
{
var productDetails = SessionRepository.GetSessionObject<List<ProductDetails>>(ApplicationConstants.sesProductDetails).ToList(); //.AsEnumerable();
//Return converted list<T> as DataTable
var dataTable = ToDataTable<ProductDetails>(productDetails);
if (dataTable != null)
{
productHeader.ProductDetailsDataTable = dataTable;
//SessionRepository.CacheSession<DataColumnCollection>(ApplicationConstants.sesAcquireStockDataColumnCollection, dataColumnCollection);
}
return View(productHeader);
}
productHeader.ProductDetailsDataTable = null;
return View(productHeader);
}
I created a generic method that takes care of transforming my data to datatable by passing in the columns names and rows respectively without having to display every value for model properties. I want it to passing the field with values that are not "" or null. so that the grid displays it. My generic method is as follows:
//Converts Generic List to DataTable
private DataTable ToDataTable<T>(List<T> data)// T is any generic type
{
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(T));
int columnCount = 0;
DataTable table = new DataTable();
var colums = rtxVending.Web.Repositories.SessionRepository.GetSessionObject<IList<rtxVending.Web.Models.ProductCategoryTags>>(ApplicationConstants.sesProductsHeaderCategoryTags);
if (colums != null && colums.Count > 0)
{
var columnName = colums.Select(a => a.ValueX).ToArray();
for (int i = 0; i < columnName.Count(); i++)
{
table.Columns.Add(columnName[i]);
}
columnCount = columnName.Count();
}
else
{
for (int i = 0; i < props.Count; i++)
{
PropertyDescriptor prop = props[i];
table.Columns.Add(prop.Name, prop.PropertyType);
}
}
object[] values = new object[props.Count];
foreach (T item in data)
{
for (int i = 0; i < values.Length; i++)
{
values[i] = props[i].GetValue(item);
}
object[] newValues = new object[columnCount];
int j = 0;
foreach (var p in values)
{
Type argType = p.GetType();
if (argType == typeof(bool) && !((bool)p))
{
newValues[j] = p;
j++;
}
else if(argType == typeof(int) && (int)p != 0)
{
newValues[j] = p;
j++;
}
else if (argType == typeof(double) && (double)p != 0)
{
newValues[j] = p;
j++;
}
else if (argType == typeof(string) && p != null && p != string.Empty)
{
newValues[j] = p;
j++;
}
if (j >= columnCount)
break;
}
//table.Rows.Add(values);
//table.Rows.Add(newValues);
}
return table;
}
My Grid is now this
#(Html.Kendo()
//.Grid<rtxVending.Web.Models.ProductDetails>()
.Grid(Model.ProductDetailsDataTable)
.Name("ProductDetailGrid")//.ClientDetailTemplateId("")
.HtmlAttributes(new { #style = "align:center; font-size:9px;" })
.Columns(columns =>
{
//var columnData = rtxVending.Web.Repositories.SessionRepository.GetSessionObject<System.Data.DataColumnCollection>(ApplicationConstants.sesAcquireStockDataColumnCollection);
//if(columnData != null && columnData.Count > 0)
if (Model.ProductDetailsDataTable != null)
foreach (System.Data.DataColumn column in Model.ProductDetailsDataTable.Columns)
{
columns.Bound(column.ColumnName);
}
})
.Pageable(pager => pager.Refresh(true))
.Sortable()
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetProductDetailsGrid", "Products"))
.Model(model =>
{
if (Model.ProductDetailsDataTable != null)
foreach (System.Data.DataColumn column in Model.ProductDetailsDataTable.Columns)
{
model.Field(column.ColumnName, column.DataType);
}
})
.Events(events => events.Error("error_handler")))
)
If there any thing i need to explain, i will respond asap. Thank Prof. Pickle!

Related

How to use select tag in kendo ui grid in ASP.NET MVC 5?

I trying to use kendo ui for first time,i want to create kendo ui that has a list of some roles for users.so i need to have a row with UserName and ... list of roles.but i do not know how to create this row!
this is my usermodel:
public class UserViewModel
{
public string password { get; set; }
public string ConfirmPassword { get; set; }
public string UserName { get; set; }
public List<IdentityRole> Roles { get; set; }
}
and this is user service:
private ApplicationDbContext db = new ApplicationDbContext();
private IList<UserViewModel> GetAll()
{
var allusers = HttpContext.Current.Session["AllCountries"] as
IList<UserViewModel>;
if (allusers == null)
{
allusers = db.Users.Select(s => new UserViewModel
{
UserName = s.UserName,
}).ToList();
HttpContext.Current.Session["AllPerson"] = allusers;
}
return allusers;
}
public IEnumerable<UserViewModel> Read()
{
return GetAll();
}
public void Create(UserViewModel myuser)
{
var store = new UserStore<ApplicationUser>(db);
var manager = new ApplicationUserManager(store);
var CustomEmail = new Guid().ToString() + "#gmail.com";
manager.Create(new ApplicationUser
{
Id = new Guid().ToString(),
UserName = myuser.UserName,
Email = CustomEmail
}, myuser.password);
db.SaveChanges();
}
public void Update(UserViewModel vwusers)
{
if (vwusers.UserName!=null)
{
var store = new UserStore<ApplicationUser>(db);
var manager = new ApplicationUserManager(store);
var objCountry = manager.FindByName(vwusers.UserName);
if (objCountry != null)
{
objCountry.UserName = vwusers.UserName;
db.Entry(objCountry).State =
System.Data.Entity.EntityState.Modified;
db.SaveChanges();
}
}
}
and my view:
...
#(Html.Kendo().Grid<UserViewModel>()
.Name("Grid").Sortable()
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.Columns(col =>
{
col.Bound(x => x.UserName).Filterable(ftb => ftb.Cell(cell =>
cell.Operator("contains").SuggestionOperator(FilterType.Contains)));
col.Bound(x => x.password).Visible(false);
col.Bound(x => x.ConfirmPassword).Visible(false);
col.Command(e => e.Edit().Text("Edit"));
col.Command(e => e.Destroy().Text("Delete"));
})
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.ToolBar(s => s.Create().Text("AddCountry"))
.Pageable(page =>
page.Refresh(true).PageSizes(true).ButtonCount(5))
.ClientDetailTemplateId("Test")
.DataSource(ds =>
ds.Ajax()
.Model(m => {
m.Id(a => a.UserName);
m.Field(p => p.Roles).DefaultValue(new List<IdentityRole>());
})
.PageSize(10)
.Events(events => events.Error("error_handler"))
.Read(r => r.Action("ReadMasters", "User"))
.Create(c => c.Action("AddNewMaster", "User").Type(HttpVerbs.Post))
.Update(c => c.Action("UpdateMaster", "User"))
.Destroy(c => c.Action("DeleteMaster", "User"))
)
.Events(e => e.DataBound("dataBound"))
)
but i dont know how to display roles as a list for create and update!
Thanks in advance for your help

Kendo treeview expander not coming

i am creating one Kendo treeview as written below
#(Html.Kendo().TreeView()
.Name("treeview")
.Template("<a class='edit-link' onclick=javascript:EditNode(#= item.id #) href='\\#'>#= item.text #</a> <a class='add-link' onclick=javascript:AddNode(#= item.id #) href='\\#'>Add</a>")
.HtmlAttributes(new { #class = "demo-section" })
.DataSource(source =>
{
source.Read(read => read.Action("Read_TemplateData", "Role"));
})
)
and in the controller action i am returning like
public ActionResult Read_TemplateData(string id)
{
IEnumerable<KendoTreeviewModel> result;
var AllPrivileges = ContextService.GetAllPrivilege(Evry.Ecompanion.Web.Common.SessionManager.AuthorizedInfo.UserId);
if (string.IsNullOrEmpty(id))
{
result = AllPrivileges.Where(p => p.Id == p.ParentPrivilegeId).Select(p => new KendoTreeviewModel { text = p.Name, id = p.Id,expanded=false, items = GetChilderns(p.Id) }).ToList();
}
else
{
result = AllPrivileges.Where(p => p.ParentPrivilegeId == Convert.ToInt32(id, CultureInfo.InvariantCulture) && p.Id != Convert.ToInt32(id, CultureInfo.InvariantCulture)).Select(p => new KendoTreeviewModel { text = p.Name, id = p.Id}).ToList();
}
return Json(result, JsonRequestBehavior.AllowGet);
}
public List<KendoTreeviewModel> GetChilderns(int id)
{
var AllPrivileges = ContextService.GetAllPrivilege(Evry.Ecompanion.Web.Common.SessionManager.AuthorizedInfo.UserId);
return AllPrivileges.Where(p => p.ParentPrivilegeId == Convert.ToInt32(id, CultureInfo.InvariantCulture) && p.Id != Convert.ToInt32(id, CultureInfo.InvariantCulture)).Select(p => new KendoTreeviewModel { text = p.Name, id = p.Id }).ToList();
}
and the viewmodel is like
public class KendoTreeviewModel
{
[DataMember]
public int id { get; set; }
[DataMember]
public string text { get; set; }
[DataMember]
public bool expanded { get; set; }
[DataMember]
public List<KendoTreeviewModel> items { get; set; }
}
in the result the Parent and child lists are coming, but the expander in the treeview is not coming
the output is coming without treeview expander, only parent nodes are displaying.
please anybody help me in resolving the issue.
Thanks in advance,
Rudresh
you are not passing Id to your controller
source.Read(read => read.Action("Read_TemplateData", "Role", new{id=#= item.id #}));
You need hasChildren property in order to get the child records
in KendoTreeviewModel class add this property hasChildren then
change
result = AllPrivileges.Where(p => p.Id == p.ParentPrivilegeId).Select(p => new KendoTreeviewModel { text = p.Name, id = p.Id,expanded=false, items = GetChilderns(p.Id) }).ToList();
to
result = AllPrivileges.Where(p => p.Id == p.ParentPrivilegeId).Select(p => new KendoTreeviewModel { text = p.Name, id = p.Id,expanded=false, items = GetChilderns(p.Id),
hasChildren = GetChilderns(p.Id).count() > 0}).ToList();

Custom Paging for ASP.Net MVC Kendo Grid

I have a MVC Kendo Grid as follows. It is working fine with default paging.
Now, I want to do custom paging. In the controller action we need to know the current page index. Also it should set the “total” count for the grid. [The actual data source will have only 2 records at a time even if there are 100 records in the database. So the grid must know the total number of records in database using “total” attribute.]
The query should return only 2 records from the database at a time.
How can we do this custom server paging using the MVC wrapper for Kendo Grid?
#using (Html.BeginForm())
{
#(Html.Kendo().Grid<KendoUIMvcSample.Models.Sample>()
.Name("ssgrid222")
.Columns(columns => {
columns.Bound(p => p.SampleDescription).Filterable(false).Width(100);
columns.Bound(p => p.SampleCode).Filterable(false).Width(100);
columns.Bound(p => p.SampleItems).Filterable(false).Width(100);
})
.AutoBind(false)
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(2)
.Read(read => read.Action("Orders_Read", "Sample")
)
)
)
}
Controller
public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request)
{
int currentPageNumber = request.Page;
return Json(GetOrders().ToDataSourceResult(request));
}
It is defined in the kendo site
CONTROLLER CODE
//Paging and Sorting
int currentPage = request.Page;
int pageSize = request.PageSize;
string sortDirection = "ASC";
string sortField = "UpdatedDateTime";
if (request.Sorts != null && request.Sorts.Count > 0)
{
sortField = request.Sorts[0].Member;
sortDirection = request.Sorts[0].SortDirection.ToString();
}
//Setting the TOTAL
var result = new DataSourceResult()
{
Data = orders,
Total = total // Total number of records
};
return Json(result);
VIEW
<div class="GridSearch">
#(Html.Kendo().Grid<MVC.Models.TransactionHistoryModel>()
.Name("TransactionHistroyGrid")
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(25)
.ServerOperation(true)
.Read(read => read
.Action("TransactionHistorySearch_Read", "TransactionHistoryResults")
.Data("additionalData")
)
)
.Columns(columns =>
{
columns.Bound(p => p.UserId).Filterable(false).Width(40).Title("Userid");
columns.Bound(p => p.Reviewed).Template(#<text></text>).ClientTemplate("<input id='checkbox' class='chkbx' type='checkbox' />").Filterable(false).Width(30).Title("Reviewed");
columns.Bound(p => p.CreatedOnEnd).Format("{0:MM/dd/yyyy}").Filterable(false).Width(50).Title("Created On");
columns.Bound(p => p.UpdatedOnEnd).Format("{0:MM/dd/yyyy}").Filterable(false).Width(50).Title("Updated On");
columns.Bound(p => p.Comment).Filterable(false).Width(50).Title("Comment");
})
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.HtmlAttributes(new { style = "height:325px;" })
)
</div>
Here is a custom paging solution we have implemented for Kendo ListView. With minor modification it should work for the grid. The solution consists of a custom DataSoure Object and a custom JSonResult class.
The custom data source:
public class MyDataSource
{
public object AggregateResults { get; set; }
public object Data { get; set; }
public object Errors { get; set; }
public int Total { get; set; }
}
The custom ActionResult:
public class JsonNetResult : ActionResult
{
public Encoding ContentEncoding { get; set; }
public string ContentType { get; set; }
public object Data { get; set; }
public JsonSerializerSettings SerializerSettings { get; set; }
public Formatting Formatting { get; set; }
public JsonNetResult()
{
SerializerSettings = new JsonSerializerSettings();
}
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
throw new ArgumentNullException("context");
HttpResponseBase response = context.HttpContext.Response;
response.ContentType = !string.IsNullOrEmpty(ContentType)
? ContentType
: "application/json";
if (ContentEncoding != null)
response.ContentEncoding = ContentEncoding;
if (Data != null)
{
var writer = new JsonTextWriter(response.Output) { Formatting = Formatting };
JsonSerializer serializer = JsonSerializer.Create(SerializerSettings);
serializer.Serialize(writer, Data);
writer.Flush();
}
}
A Typical use in an action method would be:
public ActionResult Orders_Read([DataSourceRequest] Object request)
{
int count = 0;
var ds = (DataSourceRequest)request;
var ListOfItemsToDisplay = GetItemsWithPagingInfo
(
MySearchParameters,
ds.PageSize,
ds.Page,
out count
);
return new JsonNetResult
{
Formatting = Formatting.Indented,
Data = new MyDataSource
{
Data = ListOfItemsToDisplay
Total = count,
AggregateResults = null,
Errors = null
}
};
}

Custom Ajax Binding does not work properly

I have following code for Custom Ajax Binding. This has following problems even though it is displaying data for the first page.
• The request.Sorts is coming as NULL in to the Orders_Read method
• The request.PageSize is coming as 0 to the Orders_Read method
• The request.Page is coming as 1 to the Orders_Read method (even if I click on the page 2)
What changes need to be done here to get proper sort and pagesize values?
Note: I am using MVC Wrapper for Kendo Grid.
VIEW
#Scripts.Render("~/bundles/jquery")
<script type ="text/javascript">
$(document).ready(function (){
$('#Submit1').click(function () {
alert('1');
$('#grid12').data('kendoGrid').dataSource.read();
});
});
</script>
#model KendoPratapSampleMVCApp.Models.Sample
#{
ViewBag.Title = "CustomAjaxbind";
}
<h2>CustomAjaxbind</h2>
#using (Html.BeginForm("PostValues", "CustomAjaxBinding", FormMethod.Post))
{
<input id="Submit1" type="button" value="SubmitValue" />
#(Html.Kendo().Grid<KendoPratapSampleMVCApp.Models.Sample>()
.Name("grid12")
.EnableCustomBinding(true)
.Columns(columns => {
columns.Bound(p => p.SampleDescription).Filterable(false).Width(100);
columns.Bound(p => p.SampleCode).Filterable(false).Width(100);
columns.Bound(p => p.SampleItems).Filterable(false).Width(100);
})
.Pageable()
.Sortable()
.Scrollable()
.AutoBind(false)
.Filterable()
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(2)
.Read(read => read.Action("Orders_Read", "CustomAjaxBinding"))
)
)
}
Controller
public class CustomAjaxBindingController : Controller
{
//
// GET: /CustomAjaxBinding/
public ActionResult Index()
{
return View("CustomAjaxbind");
}
public ActionResult Orders_Read([DataSourceRequest(Prefix = "grid12")]DataSourceRequest request)
{
string sortField = "SampleDescription";
string sortDirection = string.Empty;
if (request.Sorts != null)
{
foreach (SortDescriptor sortDescriptor in request.Sorts)
{
sortField = sortDescriptor.Member;
if (sortDescriptor.SortDirection == ListSortDirection.Ascending)
{
sortDirection = "Ascending";
}
else
{
sortDirection = "Descending";
}
}
}
int total = 1;
int myPageSize = 2;
if(request.PageSize !=0)
{
myPageSize = request.PageSize;
}
IEnumerable<Sample> currentSamples = GetSubsetEmployees(request.Page - 1, myPageSize, out total, sortField, sortDirection);
var result = new DataSourceResult()
{
Data = currentSamples,
Total = total // Total number of records
};
return Json(result);
}
public IEnumerable<Sample> GetSubsetEmployees(int pageIndex, int pageSize, out int itemCount, string sortField, string sortDirection)
{
IEnumerable<Sample> samples = GetSamples();
itemCount = samples.ToList().Count;
var selector = new Func<Sample, object>(e => e.GetType().GetProperty(sortField).GetValue(e, null));
var query = sortDirection.Equals("descending", StringComparison.OrdinalIgnoreCase)
? samples.OrderByDescending(selector)
: samples.OrderBy(selector);
List<Sample> currentPageEmployees = query
.Skip(pageIndex * pageSize)
.Take(pageSize)
.ToList();
return currentPageEmployees;
}
public static IEnumerable<Sample> GetSamples()
{
List<Sample> sampleAdd = new List<Sample>();
Sample s12 = new Sample();
s12.SampleCode = "1";
s12.SampleDescription = "A";
s12.SampleItems = "newone";
Sample s2 = new Sample();
s2.SampleCode = "2";
s2.SampleDescription = "B";
s2.SampleItems = "oldone";
Sample s3 = new Sample();
s3.SampleCode = "3";
s3.SampleDescription = "C";
s3.SampleItems = "latestone";
Sample s4 = new Sample();
s4.SampleCode = "4";
s4.SampleDescription = "D";
s4.SampleItems = "latestoneitem";
sampleAdd.Add(s12);
sampleAdd.Add(s2);
sampleAdd.Add(s3);
sampleAdd.Add(s4);
return sampleAdd;
}
}
Model
namespace KendoUIMvcSample.Models
{
public class SampleModel
{
public List<Sample> samples;
}
public class Sample
{
public string SampleDescription { get; set; }
public string SampleCode { get; set; }
public string SampleItems { get; set; }
}
}
I had the same problem as yours and finally found the solution recently after consuming days on investigating the problem. I post it here if someone else faced the same issue.
You need to remove Prefix from your parameter:
public ActionResult Orders_Read([DataSourceRequest(Prefix = "grid12")]DataSourceRequest request)
Converted to:
public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request)
I don't know if this is a bug from Kendo or not! But in this scenario grid can't be found by Prefix defined.
You can find an example here

Only parameterless constructors and initializers are supported in LINQ to Entities

There are several same questions that have same problem. But I cant find solution for me.
LinQ
var result = (from a in entity.TblAnalizorReadings
group a by new { date = new DateTime(((DateTime)a.okuma_tarihi).Year, ((DateTime)a.okuma_tarihi).Month, ((DateTime)a.okuma_tarihi).Day, ((DateTime)a.okuma_tarihi).Hour, 0, 0) } into g
select new AnalizorPivotChartModel
{
okuma_tarihi = g.Key.date,
Gerilim_Faz1 = g.Max(x => x.Gerilim_Faz1),
Gerilim_Faz2 = g.Max(x => x.Gerilim_Faz2),
Gerilim_Faz3 = g.Max(x => x.Gerilim_Faz3)
}).ToList();
Model
public class AnalizorPivotChartModel
{
public Nullable<System.DateTime> okuma_tarihi { get; set; }
public Nullable<decimal> Gerilim_Faz1 { get; set; }
public Nullable<decimal> Gerilim_Faz2 { get; set; }
public Nullable<decimal> Gerilim_Faz3 { get; set; }
}
I get error message as this question title. I can write more code if its neccesary.
Thanks.
var result = entity.TblAnalizorReadings
.GroupBy(a =>
new {
((DateTime)a.okuma_tarihi).Year,
((DateTime)a.okuma_tarihi).Month,
((DateTime)a.okuma_tarihi).Day,
((DateTime)a.okuma_tarihi).Hour
},
(k, g) => new {
okuma_tarihi = k,
Gerilim_Faz1 = g.Max(x => x.Gerilim_Faz1),
Gerilim_Faz2 = g.Max(x => x.Gerilim_Faz2),
Gerilim_Faz3 = g.Max(x => x.Gerilim_Faz3)
})
.AsEnumerable()
.Select(g => new AnalizorPivotChartModel
{
okuma_tarihi = new DateTime(okuma_tarihi.Year, okuma_tarihi.Month, okuma_tarihi.Day, okuma_tarihi.Hour, 0, 0),
Gerilim_Faz1 = g.Gerilim_Faz1,
Gerilim_Faz2 = g.Gerilim_Faz2,
Gerilim_Faz3 = g.Gerilim_Faz3
})
.ToList();

Resources