none
JSon file created thru Linc: Records are not distinct RRS feed

  • Question

  • ===============================================================

    frmMain

    ===============================================================

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using ErrorLog;
    using Microsoft.Office.Interop.Excel;

    namespace CambridgeToyota
    {
        public partial class frmMain : Form
        {
            public frmMain()
            {
                Microsoft.Office.Interop.Excel.Application oXLFrom;
                Microsoft.Office.Interop.Excel.Application oXLFromLookup;
                _Workbook oWBFrom = null;
                _Workbook oWBFromLookup = null;
                string strFile = "", strFileLookup = "";
                int x = 7, y = 0, intRows = 0, intReturn = 0, intRowsLookup = 0;
                var lstOrders = new List<Tuple<string, string, int, string, string, string, string>>();
                var lstOrdersLookup = new List<Tuple<string, string, string, string>>();
                DialogResult? result = null;

                InitializeComponent();
                FormClosing += FrmMain_FormClosing;
                if (SharedCode.CreateLogFolders(ProductName) == -1)
                    Environment.Exit(0);
                oXLFrom = new Microsoft.Office.Interop.Excel.Application();
                oXLFromLookup = new Microsoft.Office.Interop.Excel.Application();

                //Main Spreadsheet of Orders
                try
                {
                    //x = x / y;
                    result = dlgSelFile.ShowDialog();
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("frmMain.ShowDialog Method:  " + ex.Message, "Call Information Technology",
                                                         System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    LogError.Log(ex, "Select Kanban\\Skid File", "C:\\LogFile\\xxx\\ErrorLog", "frmMain.ShowDialog Method:");
                    CloseExcelProcesses_dll.Program.CloseProjectExcelFiles(ref oXLFrom, ref oXLFromLookup);
                    CloseExcelProcesses_dll.Program.Main();
                    Environment.Exit(0);
                }

                if (result == DialogResult.OK) // Test result.
                {
                    strFile = this.dlgSelFile.FileName;
                }
                else
                {
                    CloseExcelProcesses_dll.Program.CloseProjectExcelFiles(ref oXLFrom, ref oXLFromLookup);
                    CloseExcelProcesses_dll.Program.Main();
                    Environment.Exit(0);
                }

                try
                {
                    //File of invoice records to parse
                    //x = x / y;
                    oWBFrom = oXLFrom.Workbooks.Open(@strFile);
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("frmMain.(Open File):  " + ex.Message, "Call Information Technology",
                                                         System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    LogError.Log(ex, "Open Excel File", "C:\\LogFile\\xxx\\ErrorLog", "frmMain.(Open File):");
                    CloseExcelProcesses_dll.Program.CloseProjectExcelFiles(ref oXLFrom, ref oXLFromLookup);
                    CloseExcelProcesses_dll.Program.Main();
                    Environment.Exit(0);
                }


                //Lookup Spreadsheet for Orders for Palletization
                dlgSelFile.Title = "Select Kinbad/Skid Palletization LOOKUP file to Process";

                try
                {
                    //x = x / y;
                    result = dlgSelFile.ShowDialog();
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("frmMain.ShowDialog Method:  " + ex.Message, "Call Information Technology",
                                                         System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    LogError.Log(ex, "Select Kanban\\Skid LOOKUP File", "C:\\LogFile\\xxx\\ErrorLog", "frmMain.ShowDialog Method:");
                    oWBFrom.Close();
                    CloseExcelProcesses_dll.Program.CloseProjectExcelFiles(ref oXLFrom, ref oXLFromLookup);
                    CloseExcelProcesses_dll.Program.Main();
                    Environment.Exit(0);
                }

                if (result == DialogResult.OK) // Test result.
                {
                    strFileLookup = this.dlgSelFile.FileName;
                }
                else
                {
                    oWBFrom.Close();
                    CloseExcelProcesses_dll.Program.CloseProjectExcelFiles(ref oXLFrom, ref oXLFromLookup);
                    CloseExcelProcesses_dll.Program.Main();
                    Environment.Exit(0);
                }

                try
                {
                    //x = x / y;
                    //File of invoice records to parse
                    oWBFromLookup = oXLFromLookup.Workbooks.Open(@strFileLookup);
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("frmMain.(Open LOOKUP File):  " + ex.Message, "Call Information Technology",
                                                         System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    LogError.Log(ex, "Open Excel LOOKUP File", "C:\\LogFile\\xxx\\ErrorLog", "frmMain.(Open LOOKUP File):");
                    oWBFrom.Close();
                    CloseExcelProcesses_dll.Program.CloseProjectExcelFiles(ref oXLFrom, ref oXLFromLookup);
                    CloseExcelProcesses_dll.Program.Main();
                    Environment.Exit(0);
                }

                lblInitProgress.Text = "Processing...";
                foreach (Worksheet sheet in oWBFrom.Worksheets)
                {
                    intRows = SharedCode.TotRowSSCnt(sheet);
                }

                foreach (Worksheet sheet in oWBFromLookup.Worksheets)
                {
                    intRowsLookup = SharedCode.TotRowSSCnt(sheet);
                }

                intReturn = FillList.Orders(oWBFrom, oWBFromLookup, ref lstOrders, intRows, ref lstOrdersLookup, intRowsLookup);
                oWBFrom = null;
                oWBFromLookup = null;
                CloseExcelProcesses_dll.Program.CloseProjectExcelFiles(ref oXLFrom, ref oXLFromLookup);
                CloseExcelProcesses_dll.Program.Main();
                Environment.Exit(0);
            }

            private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
            {
                dlgSelFile.Dispose();
            }

        }
    }

    ============================================================================

    FillList class

    ============================================================================

    using Microsoft.Office.Interop.Excel;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Newtonsoft.Json.Linq;
    using Newtonsoft.Json;
    using System.IO;

    namespace CambridgeToyota
    {
        public static class FillList
        {
            const int PART_NUM = 6;
            const int SUPPLIER = 7;
            const int QPC = 18;
            const int ORDER = 24;
            const int DOCK = 26;
            const int PLANT = 27;
            const int PO_NUM = 28;
            const int PO_NUM_LOOKUP = 4;
            const int LINE_SIDE_ADDRESS_LOOKUP = 5;
            const int PALLET_LOOKUP = 6;
            const int SKIDID_LOOKUP = 7;

            public static string kanban { get; private set; }

            public static int Orders(_Workbook oWBFrom, _Workbook oWBFromLookup, ref List<Tuple<string, string, int, string, string, string, string>> lstOrders, int intRows,
                                     ref List<Tuple<string, string, string, string>> lstOrdersLookup, int intRowsLookup)
            {
                _Worksheet oSheet;
                string strPartNum = "", strOrderNum = "", strSupplier = "", strDock = "", strPlant = "", strPONum = "";
                string strLinSideAddr = "", strPallet = "", strSkidID = "", strJSonFile = "";
                int i, k = 0, intQPC;
                var lstOrdersSorted = new List<Tuple<string, string, int, string, string, string, string>>();
                List<Tuple<string, string>> lstGroupCnts = new List<Tuple<string, string>>();
                var lstOrdersLookupSorted = new List<Tuple<string, string, int, string, string, string, string>>();
                var lstOrdersLookupClone = new List<Tuple<string, string, string, string>>();
                //string json;

                oSheet = (_Worksheet)oWBFrom.ActiveSheet;

                for (i = 2; i <= intRows; i++)
                {
                    strPartNum = oSheet.Cells[i, PART_NUM].Text;
                    strSupplier = oSheet.Cells[i, SUPPLIER].Text;
                    intQPC = Convert.ToInt32(oSheet.Cells[i, QPC].Text);
                    strOrderNum = oSheet.Cells[i, ORDER].Text;
                    strDock = oSheet.Cells[i, DOCK].Text;
                    strPlant = oSheet.Cells[i, PLANT].Text;
                    strPONum = oSheet.Cells[i, PO_NUM].Text;
                    lstOrders.Add(new Tuple<string, string, int, string, string, string, string>(strPartNum, strSupplier, intQPC,
                                                                                                 strOrderNum, strDock, strPlant, strPONum));
                }

                oSheet = (_Worksheet)oWBFromLookup.ActiveSheet;
                for (i = 2; i <= intRowsLookup; i++)
                {
                    strPONum = oSheet.Cells[i, PO_NUM_LOOKUP].Text;
                    strLinSideAddr = oSheet.Cells[i, LINE_SIDE_ADDRESS_LOOKUP].Text;
                    strPallet = oSheet.Cells[i, PALLET_LOOKUP].Text;
                    strSkidID = oSheet.Cells[i, SKIDID_LOOKUP].Text;
                    lstOrdersLookup.Add(new Tuple<string, string, string, string>(strPONum, strLinSideAddr, strPallet, strSkidID));
                }

                lstOrdersLookupClone = lstOrdersLookup;
                lstOrdersSorted = lstOrders.OrderBy(a => a.Item7).ToList();
                var lstOrdersGrouped = lstOrdersSorted
                    .GroupBy(ac => new
                    {
                        ac.Item7
                    })
                    .Select(ac => new { PONum = ac.Key.Item7, Cnt = ac.Count() });

                strPONum = "";
                foreach (var lst in lstOrdersSorted)
                {
                    if (strPONum == lst.Item7.ToString())
                        k--;
                    else
                        k = lstOrdersGrouped.First(a => a.PONum == lst.Item7.ToString()).Cnt;

                    strPONum = lst.Item7.ToString();
                    lstGroupCnts.Add(new Tuple<string, string>(strPONum, k.ToString()));
                }

                //bookmark - google search on C# to create JSON
                JObject rss =
                    new JObject(
                        new JProperty("exceptions",
                            new JArray()),
                        new JProperty("skids",
                            new JArray("kanbans",
                                new JArray(JToken.FromObject(
                                    from los in lstOrdersSorted
                                    from lg in lstGroupCnts
                                        //from losLUC in lstOrdersLookupClone
                                    where (los.Item7 == lg.Item1) // && los.Item7 == losLUC.Item1)
                                    select new
                                    {
                                        kanban = los.Item7,
                                        partNumber = los.Item1,
                                        boxNumber = lg.Item2,
                                        //lineSideAddress = losLUC.Item2,
                                        qpc = los.Item3
                                    }).Distinct()
                                )
                            ),
                            new JArray("exceptions",
                                new JArray())
                    ));

                strJSonFile = "V:\\AKushner\\Testing\\xxx.json";
                if (File.Exists(strJSonFile))
                    File.Delete(strJSonFile);
                while (File.Exists(strJSonFile))
                    ;

                // write JSON directly to a file
                using (StreamWriter file = File.CreateText(@strJSonFile))
                using (JsonTextWriter writer = new JsonTextWriter(file))
                {
                    rss.WriteTo(writer);
                }

                return 1;
            }
        }
    }

    =========================================================================

    How do I get distinct rows?  group, groupby (where orderby is) doesn't work and .GroupBy as opposed to .Distinct()

    doesn't work either.  How in the world to you make the selected rows distinct?

    =========================================================================

    sample output with culprit rows set up for readability:

    =========================================================================

    {"exceptions":[],"skids":[["kanbans",[{"kanban":"B031","partNumber":"82152 0R350 00","boxNumber":"1","qpc":6},{"kanban":"B254","partNumber":"82154 0R120 00","boxNumber":"1","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"4","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"3","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"2","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"1","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"4","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"3","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"2","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"1","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"4","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"3","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"2","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"1","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"4","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"3","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"2","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"1","qpc":12},
    {"kanban":"C820","partNumber":"82152 0R320 00","boxNumber":"6","qpc":6},{"kanban":"C820","partNumber":"82152 0R320 00","boxNumber":"5","qpc":6},{"kanban":"C820","partNumber":"82152 0R320 00",

    ========================================================

    for distinct rows should appear for the kanban of "C424" and not 16.

    Monday, March 4, 2019 9:38 PM

All replies

  • Please use the code block to post code so we can read it.

    You posted a bunch of code and title. You haven't told us anything about the problem you're having and why we should read through all that code. Please tell us what issue you're having, any errors you're getting and reduce the code (in a block) down to just the relevant parts.


    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, March 5, 2019 2:54 PM
  • Did you even bother to read it? I DID SAY what the problem is.  It is:

    =========================================================================

    How do I get distinct rows?  group, groupby (where orderby is) doesn't work and .GroupBy as opposed to .Distinct()

    doesn't work either.  How in the world to you make the selected rows distinct?

    =========================================================================

    sample output with culprit rows set up for readability:

    =========================================================================

    {"exceptions":[],"skids":[["kanbans",[{"kanban":"B031","partNumber":"82152 0R350 00","boxNumber":"1","qpc":6},{"kanban":"B254","partNumber":"82154 0R120 00","boxNumber":"1","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"4","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"3","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"2","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"1","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"4","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"3","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"2","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"1","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"4","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"3","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"2","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"1","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"4","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"3","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"2","qpc":12},
    {"kanban":"C424","partNumber":"82171 0R640 00","boxNumber":"1","qpc":12},
    {"kanban":"C820","partNumber":"82152 0R320 00","boxNumber":"6","qpc":6},{"kanban":"C820","partNumber":"82152 0R320 00","boxNumber":"5","qpc":6},{"kanban":"C820","partNumber":"82152 0R320 00",

    ========================================================

    four distinct rows should appear for the kanban of "C424" and not 16.

    ==================================================================

    ==================================================================

    ==================================================================

    Below is the most relevant code and it is the linq at the end that is not displaying distinct rows:

    ==================================================================

    ==================================================================

    ============================================================================

    FillList class

    ============================================================================

    using Microsoft.Office.Interop.Excel;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Newtonsoft.Json.Linq;
    using Newtonsoft.Json;
    using System.IO;

    namespace CambridgeToyota
    {
        public static class FillList
        {
            const int PART_NUM = 6;
            const int SUPPLIER = 7;
            const int QPC = 18;
            const int ORDER = 24;
            const int DOCK = 26;
            const int PLANT = 27;
            const int PO_NUM = 28;
            const int PO_NUM_LOOKUP = 4;
            const int LINE_SIDE_ADDRESS_LOOKUP = 5;
            const int PALLET_LOOKUP = 6;
            const int SKIDID_LOOKUP = 7;

            public static string kanban { get; private set; }

            public static int Orders(_Workbook oWBFrom, _Workbook oWBFromLookup, ref List<Tuple<string, string, int, string, string, string, string>> lstOrders, int intRows,
                                     ref List<Tuple<string, string, string, string>> lstOrdersLookup, int intRowsLookup)
            {
                _Worksheet oSheet;
                string strPartNum = "", strOrderNum = "", strSupplier = "", strDock = "", strPlant = "", strPONum = "";
                string strLinSideAddr = "", strPallet = "", strSkidID = "", strJSonFile = "";
                int i, k = 0, intQPC;
                var lstOrdersSorted = new List<Tuple<string, string, int, string, string, string, string>>();
                List<Tuple<string, string>> lstGroupCnts = new List<Tuple<string, string>>();
                var lstOrdersLookupSorted = new List<Tuple<string, string, int, string, string, string, string>>();
                var lstOrdersLookupClone = new List<Tuple<string, string, string, string>>();
                //string json;

                oSheet = (_Worksheet)oWBFrom.ActiveSheet;

                for (i = 2; i <= intRows; i++)
                {
                    strPartNum = oSheet.Cells[i, PART_NUM].Text;
                    strSupplier = oSheet.Cells[i, SUPPLIER].Text;
                    intQPC = Convert.ToInt32(oSheet.Cells[i, QPC].Text);
                    strOrderNum = oSheet.Cells[i, ORDER].Text;
                    strDock = oSheet.Cells[i, DOCK].Text;
                    strPlant = oSheet.Cells[i, PLANT].Text;
                    strPONum = oSheet.Cells[i, PO_NUM].Text;
                    lstOrders.Add(new Tuple<string, string, int, string, string, string, string>(strPartNum, strSupplier, intQPC,
                                                                                                 strOrderNum, strDock, strPlant, strPONum));
                }

                oSheet = (_Worksheet)oWBFromLookup.ActiveSheet;
                for (i = 2; i <= intRowsLookup; i++)
                {
                    strPONum = oSheet.Cells[i, PO_NUM_LOOKUP].Text;
                    strLinSideAddr = oSheet.Cells[i, LINE_SIDE_ADDRESS_LOOKUP].Text;
                    strPallet = oSheet.Cells[i, PALLET_LOOKUP].Text;
                    strSkidID = oSheet.Cells[i, SKIDID_LOOKUP].Text;
                    lstOrdersLookup.Add(new Tuple<string, string, string, string>(strPONum, strLinSideAddr, strPallet, strSkidID));
                }

                lstOrdersLookupClone = lstOrdersLookup;
                lstOrdersSorted = lstOrders.OrderBy(a => a.Item7).ToList();
                var lstOrdersGrouped = lstOrdersSorted
                    .GroupBy(ac => new
                    {
                        ac.Item7
                    })
                    .Select(ac => new { PONum = ac.Key.Item7, Cnt = ac.Count() });

                strPONum = "";
                foreach (var lst in lstOrdersSorted)
                {
                    if (strPONum == lst.Item7.ToString())
                        k--;
                    else
                        k = lstOrdersGrouped.First(a => a.PONum == lst.Item7.ToString()).Cnt;

                    strPONum = lst.Item7.ToString();
                    lstGroupCnts.Add(new Tuple<string, string>(strPONum, k.ToString()));
                }

                //bookmark - google search on C# to create JSON
                JObject rss =
                    new JObject(
                        new JProperty("exceptions",
                            new JArray()),
                        new JProperty("skids",
                            new JArray("kanbans",
                                new JArray(JToken.FromObject(
                                    from los in lstOrdersSorted
                                    from lg in lstGroupCnts
                                        //from losLUC in lstOrdersLookupClone
                                    where (los.Item7 == lg.Item1) // && los.Item7 == losLUC.Item1)
                                    select new
                                    {
                                        kanban = los.Item7,
                                        partNumber = los.Item1,
                                        boxNumber = lg.Item2,
                                        //lineSideAddress = losLUC.Item2,
                                        qpc = los.Item3
                                    }).Distinct()
                                )
                            ),
                            new JArray("exceptions",
                                new JArray())
                    ));

    Tuesday, March 5, 2019 3:28 PM
  • Your code is unreadable. Please use the code block tool in the editor to put your code in a code block and put your question/comments outside of it. That is entirely too much code for anyone to read just to find your question.

    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, March 5, 2019 3:36 PM
  • Don't really know what you are talking about.  code block tool in the editor.  What code block tool?  What editor?  I thought you might copy my code to the Visual Studio code editor.  The Linq is not screening out duplicates:

     JObject rss =
                    new JObject(
                        new JProperty("exceptions",
                            new JArray()),
                        new JProperty("skids",
                            new JArray("kanbans",
                                new JArray(JToken.FromObject(
                                    from los in lstOrdersSorted
                                    from lg in lstGroupCnts
                                        //from losLUC in lstOrdersLookupClone
                                    where (los.Item7 == lg.Item1) // && los.Item7 == losLUC.Item1)
                                    select new
                                    {
                                        kanban = los.Item7,
                                        partNumber = los.Item1,
                                        boxNumber = lg.Item2,
                                        //lineSideAddress = losLUC.Item2,
                                        qpc = los.Item3
                                    }).Distinct()
                                )
                            ),
                            new JArray("exceptions",
                                new JArray())
                    ));

    Tuesday, March 5, 2019 5:11 PM
  • The code block editor is in the post UI.

    It allows us to see and easily copy your code without having to leave the forum window.

    As for your query, Distinct uses IEqualityComparer so the distinction is on equal objects. Since you're using an anonymous type the implementation for it will require that all property values match all other property values for two of them to be equal. I suspect that isn't happening in your case.

    To fix this you should identify the property(ies) that make up the unique identifier of the type and then define an IEqualityComparer to use it. But since you're using an anonymous type you aren't going to be able to define a custom IEqualityComparer on an anonymous type so you'd need to switch to a regular type first. Distinct doesn't have an overload that accepts just a predicate function, although you could write one, which would also solve this case and would work with an anonymous type. Perhaps something like this (untested).

    public static class EnumerableExtensions
    {
        public static IEnumerable<T> Distinct<T> ( this IEnumerable<T> source, Func<T, T, bool> comparer )
        {
            return source.Distinct(new DelegateEqualityComparer<T>(comparer));
        }
    }
    
    public class DelegateEqualityComparer<T> : IEqualityComparer<T>
    {
        public DelegateEqualityComparer( Func<T, T, bool> comparer )
        {
            _comparer = comparer;
        }
    
        public bool Equals ( T x, T y ) { return _comparer(x, y); }
        public int GetHashCode ( T obj ) { return obj?.GetHashCode() ?? 0; }
    
    
        private readonly Func<T, T, bool> _comparer;
    }
    
    //Usage
    var evens = values.Distinct((x,y) => x == y);

    Looking at your query it looks like you're joining tables together. You may consider using a group by clause instead. Group by can group by multiple properties and then return the list of items that match those. This generally produces the same set of distinct objects since the grouping would be on your "unique" values. This would eliminate the need for the distinct and would allow you to stick with the anonymous type.


    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, March 5, 2019 6:35 PM