LINQ Query returns proper count but duplicates data









up vote
0
down vote

favorite












enter image description here



I have the below query which brings the position value.
If I run the SQL query obtained from the debug window the records look okay.
But the list doesn't seem to duplicate the value for Report Date field in c#.



var query = (from AceBi in context.AceBiMonthlyDaos 
join Inst in context.Instruments on AceBi.Naid equals Inst.AceId
join FinAcct in context.FinancialAccounts on AceBi.PositionAccountKey equals
FinAcct.AceClientId where AceBi.PositionAccountKey != null
join Invst in context.Investments
on new a = Inst.Id, b = FinAcct.Id equals new a = Invst.InstrumentId, b = Invst.FinAcctId
select new AceBi, Invst).Distinct();


Output from SQL image 1
Output list in Entity image 2



enter image description here










share|improve this question























  • As you can see, the output in the list has duplicated report date value or it just picks the first reportdate value for all 3 records related to na_id/aceclientid pair
    – SPG
    Nov 11 at 1:16







  • 1




    Esp. the second list as image is extremely hard to read. Therefore it's always discouraged to use screenshots of textual output in questions. You better paste the text itself, formatted properly. That said, duplicated data always has to do with non-unique primary keys in the EF class model.
    – Gert Arnold
    Nov 11 at 14:09














up vote
0
down vote

favorite












enter image description here



I have the below query which brings the position value.
If I run the SQL query obtained from the debug window the records look okay.
But the list doesn't seem to duplicate the value for Report Date field in c#.



var query = (from AceBi in context.AceBiMonthlyDaos 
join Inst in context.Instruments on AceBi.Naid equals Inst.AceId
join FinAcct in context.FinancialAccounts on AceBi.PositionAccountKey equals
FinAcct.AceClientId where AceBi.PositionAccountKey != null
join Invst in context.Investments
on new a = Inst.Id, b = FinAcct.Id equals new a = Invst.InstrumentId, b = Invst.FinAcctId
select new AceBi, Invst).Distinct();


Output from SQL image 1
Output list in Entity image 2



enter image description here










share|improve this question























  • As you can see, the output in the list has duplicated report date value or it just picks the first reportdate value for all 3 records related to na_id/aceclientid pair
    – SPG
    Nov 11 at 1:16







  • 1




    Esp. the second list as image is extremely hard to read. Therefore it's always discouraged to use screenshots of textual output in questions. You better paste the text itself, formatted properly. That said, duplicated data always has to do with non-unique primary keys in the EF class model.
    – Gert Arnold
    Nov 11 at 14:09












up vote
0
down vote

favorite









up vote
0
down vote

favorite











enter image description here



I have the below query which brings the position value.
If I run the SQL query obtained from the debug window the records look okay.
But the list doesn't seem to duplicate the value for Report Date field in c#.



var query = (from AceBi in context.AceBiMonthlyDaos 
join Inst in context.Instruments on AceBi.Naid equals Inst.AceId
join FinAcct in context.FinancialAccounts on AceBi.PositionAccountKey equals
FinAcct.AceClientId where AceBi.PositionAccountKey != null
join Invst in context.Investments
on new a = Inst.Id, b = FinAcct.Id equals new a = Invst.InstrumentId, b = Invst.FinAcctId
select new AceBi, Invst).Distinct();


Output from SQL image 1
Output list in Entity image 2



enter image description here










share|improve this question















enter image description here



I have the below query which brings the position value.
If I run the SQL query obtained from the debug window the records look okay.
But the list doesn't seem to duplicate the value for Report Date field in c#.



var query = (from AceBi in context.AceBiMonthlyDaos 
join Inst in context.Instruments on AceBi.Naid equals Inst.AceId
join FinAcct in context.FinancialAccounts on AceBi.PositionAccountKey equals
FinAcct.AceClientId where AceBi.PositionAccountKey != null
join Invst in context.Investments
on new a = Inst.Id, b = FinAcct.Id equals new a = Invst.InstrumentId, b = Invst.FinAcctId
select new AceBi, Invst).Distinct();


Output from SQL image 1
Output list in Entity image 2



enter image description here







linq-to-sql linq-to-entities






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 8:12









Mohammad

13.1k93158




13.1k93158










asked Nov 11 at 1:14









SPG

113




113











  • As you can see, the output in the list has duplicated report date value or it just picks the first reportdate value for all 3 records related to na_id/aceclientid pair
    – SPG
    Nov 11 at 1:16







  • 1




    Esp. the second list as image is extremely hard to read. Therefore it's always discouraged to use screenshots of textual output in questions. You better paste the text itself, formatted properly. That said, duplicated data always has to do with non-unique primary keys in the EF class model.
    – Gert Arnold
    Nov 11 at 14:09
















  • As you can see, the output in the list has duplicated report date value or it just picks the first reportdate value for all 3 records related to na_id/aceclientid pair
    – SPG
    Nov 11 at 1:16







  • 1




    Esp. the second list as image is extremely hard to read. Therefore it's always discouraged to use screenshots of textual output in questions. You better paste the text itself, formatted properly. That said, duplicated data always has to do with non-unique primary keys in the EF class model.
    – Gert Arnold
    Nov 11 at 14:09















As you can see, the output in the list has duplicated report date value or it just picks the first reportdate value for all 3 records related to na_id/aceclientid pair
– SPG
Nov 11 at 1:16





As you can see, the output in the list has duplicated report date value or it just picks the first reportdate value for all 3 records related to na_id/aceclientid pair
– SPG
Nov 11 at 1:16





1




1




Esp. the second list as image is extremely hard to read. Therefore it's always discouraged to use screenshots of textual output in questions. You better paste the text itself, formatted properly. That said, duplicated data always has to do with non-unique primary keys in the EF class model.
– Gert Arnold
Nov 11 at 14:09




Esp. the second list as image is extremely hard to read. Therefore it's always discouraged to use screenshots of textual output in questions. You better paste the text itself, formatted properly. That said, duplicated data always has to do with non-unique primary keys in the EF class model.
– Gert Arnold
Nov 11 at 14:09












1 Answer
1






active

oldest

votes

















up vote
0
down vote













try convert it to dictionary first



Dictionary<int, DateTime> existingItems = 
(from ObjType ot in TableObj).ToDictionary(x => x.Key);





share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244992%2flinq-query-returns-proper-count-but-duplicates-data%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    try convert it to dictionary first



    Dictionary<int, DateTime> existingItems = 
    (from ObjType ot in TableObj).ToDictionary(x => x.Key);





    share|improve this answer
























      up vote
      0
      down vote













      try convert it to dictionary first



      Dictionary<int, DateTime> existingItems = 
      (from ObjType ot in TableObj).ToDictionary(x => x.Key);





      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        try convert it to dictionary first



        Dictionary<int, DateTime> existingItems = 
        (from ObjType ot in TableObj).ToDictionary(x => x.Key);





        share|improve this answer












        try convert it to dictionary first



        Dictionary<int, DateTime> existingItems = 
        (from ObjType ot in TableObj).ToDictionary(x => x.Key);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 8:24









        dev stack

        61




        61



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244992%2flinq-query-returns-proper-count-but-duplicates-data%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            27

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            Category:Rhetoric