Search code examples
c#linqentity-frameworkasp.net-mvc-5poco

EF6 Code First Change Data Value


I'm developing a web application and I'm making queries to my database to bring the information, which I worked correctly, but now something strange is happening.

I have a CustomerRates table, which has the following fields:

  • Cus_ID
  • svCode
  • svRateDisc
  • svBasicDisc
  • svMinCharge
  • svFutile
  • svWaitingTime
  • svWaitingTimeFree

I'm trying to bring data and paint them in a grid, but when I start to carefully review the values ​​do not correspond to those that are in the database, I mean the information brings, but the values ​​change and that only happens when the client ID is the same. This is happening and I don't know why:

Original value (the one in the table):

┌───────┬───────┬───────────┬────────────┬────────────┬─────────┬──────────────┬──────────────────┐
│Cus_ID │svCode │svRateDisc │svBasicDisc │svMinCharge │svFutile │svWaitingTime │svWaitingTimeFree │
├───────┼───────┼───────────┼────────────┼────────────┼─────────┼──────────────┼──────────────────┤
│21901  │FLW    │0.4        │5           │7           │12       │0             │0                 │
├───────┼───────┼───────────┼────────────┼────────────┼─────────┼──────────────┼──────────────────┤
│20650  │FLW    │0.4        │5           │7           │12       │0             │0                 │
├───────┼───────┼───────────┼────────────┼────────────┼─────────┼──────────────┼──────────────────┤
│20650  │STD    │0.7        │5.5         │7.5         │15       │0             │0                 │
├───────┼───────┼───────────┼────────────┼────────────┼─────────┼──────────────┼──────────────────┤
│20650  │C250   │1.4        │11          │22          │25       │0             │0                 │
├───────┼───────┼───────────┼────────────┼────────────┼─────────┼──────────────┼──────────────────┤
│20995  │C250   │1.2        │10          │20          │25       │0             │0                 │
├───────┼───────┼───────────┼────────────┼────────────┼─────────┼──────────────┼──────────────────┤
│21371  │FLW2   │0.51       │6.2         │8.5         │10       │0             │0                 │
└───────┴───────┴───────────┴────────────┴────────────┴─────────┴──────────────┴──────────────────┘

Value returned me after doing the query:

┌───────┬───────┬───────────┬────────────┬────────────┬─────────┬──────────────┬──────────────────┐
│Cus_ID │svCode │svRateDisc │svBasicDisc │svMinCharge │svFutile │svWaitingTime │svWaitingTimeFree │
├───────┼───────┼───────────┼────────────┼────────────┼─────────┼──────────────┼──────────────────┤
│21901  │FLW    │0.4        │5           │7           │12       │0             │0                 │
├───────┼───────┼───────────┼────────────┼────────────┼─────────┼──────────────┼──────────────────┤
│20650  │FLW    │0.4        │5           │7           │12       │0             │0                 │
├───────┼───────┼───────────┼────────────┼────────────┼─────────┼──────────────┼──────────────────┤
│20650  │FLW    │0.4        │5           │7           │12       │0             │0                 │
├───────┼───────┼───────────┼────────────┼────────────┼─────────┼──────────────┼──────────────────┤
│20650  │FLW    │0.4        │5           │7           │12       │0             │0                 │
├───────┼───────┼───────────┼────────────┼────────────┼─────────┼──────────────┼──────────────────┤
│20995  │C250   │1.2        │10          │20          │25       │0             │0                 │
├───────┼───────┼───────────┼────────────┼────────────┼─────────┼──────────────┼──────────────────┤
│21371  │FLW2   │0.51       │6.2         │8.5         │10       │0             │0                 │
└───────┴───────┴───────────┴────────────┴────────────┴─────────┴──────────────┴──────────────────┘

The strange thing is that it only happens with this table that the others work correctly.

Thank you very much for your help!


Solution

  • Really I don't know why this error is generated.

    My solution was to do a step by step every few methods that were being used to make the call to the monitoring entity.

    When I make the map table and define the primary key, the generation of the company is as follows:

    this.HasKey (t => t.Cus_ID);

    Replace it with this:

    this.HasKey (t => t.svCode);

    And bring me the records as it should be ..

    Still do not understand why. Thank you very much for your help