I have table class Logging
Here is code:
public partial class Logging
{
public string Imei { get; set; }
public DateTime CurDateTime { get; set; }
public Nullable<System.DateTime> GPSDateTime2 { get; set; }
public Nullable<decimal> Latitude2 { get; set; }
public Nullable<decimal> Longitude2 { get; set; }
public int Speed { get; set; }
public Nullable<int> Datatype { get; set; }
public int Id { get; set; }
}
Also I have ViewModel
public class HeatmapViewModel
{
public decimal? Latitude2 { get; set; }
public decimal? Longitude2 { get; set; }
public int FirstStartDifference { get; set; }
public int LastStartDifference { get; set; }
public int coeff = 2;
public int Difference;
}
I have method in repository where I do all calculations
Here is code
var allitems = ctx.Loggings.AsEnumerable().Select(
x => new Logging
{
Longitude2 = x.Longitude2,
Latitude2 = x.Latitude2,
CurDateTime = x.CurDateTime,
Datatype = x.Datatype
});
var filteredQuery = allitems.Where(x => x.Datatype == 1 || x.Datatype == 2).OrderByDescending(x => x.Id).ToList();
for (int i = 1; i < filteredQuery.Count; i++)
{
if (filteredQuery[i].Datatype == 2 && filteredQuery[i - 1].Datatype == 1)
{
TimeSpan differenceTicks = filteredQuery[i].CurDateTime - filteredQuery[i - 1].CurDateTime;
var differenceInMinutes = (int) differenceTicks.TotalMinutes;
}
}
items.Add(new HeatmapViewModel
{
Latitude2 = allitems.Longitude2,
Longitude2 = allitems.Longitude2,
Difference = differenceInMinutes
});
I have trouble with this block of code:
items.Add(new HeatmapViewModel
{
Latitude2 = allitems.Longitude2,
Longitude2 = allitems.Longitude2,
Difference = differenceInMinutes
});
Here is errors:
Severity Code Description Project File Line Suppression State Error CS1061 'IEnumerable' does not contain a definition for 'Longitude2' and no extension method 'Longitude2' accepting a first argument of type 'IEnumerable' could be found (are you missing a using directive or an assembly reference?) Heatmap C:\Users\nemes\source\repos\Heatmap\Heatmap\Repository\HeatmapRepository.cs 91 Active
Severity Code Description Project File Line Suppression State Error CS1061 'IEnumerable' does not contain a definition for 'Longitude2' and no extension method 'Longitude2' accepting a first argument of type 'IEnumerable' could be found (are you missing a using directive or an assembly reference?) Heatmap C:\Users\nemes\source\repos\Heatmap\Heatmap\Repository\HeatmapRepository.cs 92 Active Severity Code Description Project File Line Suppression State Error CS0103 The name 'differenceInMinutes' does not exist in the current context Heatmap C:\Users\nemes\source\repos\Heatmap\Heatmap\Repository\HeatmapRepository.cs 93 Active
How I can solve them?
var allitems = ctx.Loggings;And you need to add instance ofHeatmapViewModelinside theforloop (assumingitemsisList<HeatmapViewModel>)HeatmapViewModelin for? @StephenMueckeifblock -items.Add(new HeatmapViewModel{ Latitude2 = filteredQuery[i].Latitude2, ...., Difference = differenceInMinutes});HeatmapViewModelfor every 2nd item because of yourifblock (assuming theDatatypevalue alternates for each item in the query). Its hard to understand what you really wanting to do here