Tuesday, 20 August 2013

DistinctBy not working in C#/ Visual Studio 2012

DistinctBy not working in C#/ Visual Studio 2012

I am using DistinctBy to return a distinct list. It is somehow not
accepting the method.
public List<LastLocation> getBeatPointsWithLastPosition(List<LastLocation>
details)
{
string connectionString =
ConfigurationManager.AppSettings["CONNSTRING"].ToString();
MySqlConnection connectionObj = new
MySqlConnection(connectionString);
try
{
MySqlCommand commandObj = new
MySqlCommand("getLastCoordinate", connectionObj);
commandObj.CommandType = CommandType.StoredProcedure;
commandObj.Connection.Open();
// Problem Area Starts
List<LastLocation> tempLast = details.DistinctBy(x =>
x.deviceID).ToList();
//Problem Area Ends
for (int i = 0; i < tempLast.Count; i++)
{
List<LastLocation> tempList = (from g in details where
g.accountID == details[i].accountID && g.deviceID ==
tempLast[i].deviceID select g).ToList();
if (tempList.Count >= 1)
{
commandObj.Parameters.Add("accountID1",
tempList[0].accountID);
commandObj.Parameters.Add("deviceID1",
tempList[0].deviceID);
//pkr-start
string l_s_nearest_poi;
string l_s_new_address;
string l_ret_val;
POI l_o_poi = new POI();
//DALGisWebService l_o_gws = new DALGisWebService();
bool l_conn_flag = true;
l_ret_val = l_o_poi.dl_connect();
if (l_ret_val.CompareTo("ERROR") == 0)
{
l_conn_flag = false;
}
//pkr-end
MySqlDataReader readerObj =
commandObj.ExecuteReader();
while (readerObj.Read())
{
tempList[0].lastaddress =
readerObj["address"].ToString();
tempList[0].lastheading =
Convert.ToDouble(readerObj["heading"]);
tempList[0].lastlatitude =
Convert.ToDouble(readerObj["latitude"]);
tempList[0].lastlongitude =
Convert.ToDouble(readerObj["longitude"]);
tempList[0].lastspeedKPH =
Convert.ToDouble(readerObj["speedKPH"]);
tempList[0].laststatusCode =
(status)Convert.ToInt32(readerObj["statusCode"]);
tempList[0].lasttimestamp =
Convert.ToDateTime(readerObj["timestamp"]);
tempList[0].lastVDOP =
readerObj["odometerKM"].ToString();
try
{
if (l_conn_flag)
{
l_s_nearest_poi =
l_o_poi.dl_get_nearest_poi(tempList[0].lastlatitude,
tempList[0].lastlongitude);
if
((l_s_nearest_poi.CompareTo("ERROR")
== 0) ||
(l_s_nearest_poi.CompareTo("NA") ==
0))
{
l_s_new_address = "";
tempList[0].lastaddress =
l_s_new_address +
tempList[0].lastaddress;
}
else
{
tempList[0].lastaddress =
l_s_nearest_poi +
tempList[0].lastaddress;
}
}
else
{
l_s_new_address = "";
tempList[0].lastaddress =
l_s_new_address +
tempList[0].lastaddress;
}
// pkr - end
}
catch (Exception ex)
{
}
}
l_o_poi.dl_disconnect();
readerObj.Close();
}
}
commandObj.Dispose();
connectionObj.Close();
connectionObj.Dispose();
return details;
}
catch
{
throw;
}
finally
{
connectionObj.Close();
connectionObj.Dispose();
}
}
This was a working project a few days ago when I was using Visual Studio
2008. I migrated the project to Framework 4.0 and I am currently using
Visual Studio 2012 and suudenly this has started causing problems. Below
is the list of Namespaces being used and assemblies referenced.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COMMON;
using MySql.Data.MySqlClient;
using System.Data;
using System.Configuration;
using System.Xml.Linq;
Am I doing anything wrong?

No comments:

Post a Comment