Base solution for your next web application
Open Closed

Issue with service bringing back duplicate items #3139


User avatar
0
joe704la created

Very weird issue I am having with my Angular2 Core version. I am on 4.0.0 and in my service I have a very simple service to get a list from the database. There are only 4 items in the database with Ids of 1,2,3,4.

What I get back in the list is entity Id 1, 1 and 3, 3. So it is bringing back 4 items as it should but it is duplicating Id 1 and 3 and not giving me 2 and 4.

Below is my simple service. I haven't had this issue before version 4.0.0.

public async Task<ListResultDto<ClaimListDto>> OpenClaims()
        {
            var claim = await _claimRepository.GetAllListAsync();

            return new ListResultDto<ClaimListDto>(ObjectMapper.Map<List<ClaimListDto>>(claim));
        }

9 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Is this line returns duplicate Ids ?

    await _claimRepository.GetAllListAsync()
    

    If so, can you share your entity class and data in the database ? I will try to reproduce it.

    Thanks.

  • User Avatar
    0
    joe704la created

    Yes that is the line causing the issue.

    I can't send the data from the database as it has sensitive data. But below is the entity.

    public class Claim : IEntity<long>
        {
            [Key]
            [Column(Order = 0)]
            public long Id { get; set; }
    
            [Key]
            [Column(Order = 1, TypeName = "date")]
            public DateTime FileDate { get; set; }
    
            [StringLength(150)]
            public string EdiFileName { get; set; }
    
            [Column(TypeName = "date")]
            public DateTime? LoadDate { get; set; }
    
            [StringLength(25)]
            public string PaymentAmount { get; set; }
    
    
            [StringLength(60)]
            public string PayerID { get; set; }
    
    
            [StringLength(70)]
            public string PayerName { get; set; }
    
    
            [StringLength(60)]
            public string PayeeId { get; set; }
    
        }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Can you change your entity definition from

    public class Claim : IEntity<long>
    

    to

    public class Claim : Entity<long>
    

    and try it again ?

    Thanks.

  • User Avatar
    0
    joe704la created

    Unfortunately that did not work.

    Does this have something to do with Entity Framework Core? This didn't happen until I upgraded to 4.0

    I am using the .NET Framework 4.6.1 version not the .NET Core 1.1 version.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Lastly, can you check the executing SQL query using SQL profiler ? If you cannot find the problem with that, we can try to help you using TeamViewer or any other tool remotely.

    Thanks.

  • User Avatar
    0
    joe704la created

    I PM you.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I have read your PM, it is a strange thing really :). Can you send your project to us via email ? I think we will move faster in that way. If possible, please send your db with data or at least your db's schema as well.

    Thanks.

  • User Avatar
    0
    joe704la created

    I finally figured it out. At least this specific issue. Since these tables were already there I auto generated the classes from the database in a different project and then copied pasted them into the site. For some reason it created a key for both the Id and FileDate. So it was lumping those items together. I didn't even notice that. That is why they were duplicated. As soon as I commented it out like below it worked.

    modelBuilder.Entity<Claimpayment>()
                    .HasKey(e => e.Id);
                //modelBuilder.Entity<Claimpayment>()
                //    .HasKey(e => e.FileDate);
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks for the feedback @joe704la :).