Giter Site home page Giter Site logo

Comments (5)

alexwiese avatar alexwiese commented on June 14, 2024

Hi @EelhandsMcCoy

Check out https://github.com/alexwiese/EntityFrameworkCore.OpenEdge#gotchas

Basically EF Core thinks they are all the same record as the "ID" is the same.
You need a unique column to act as the ID. If you don't have one then add RowId as per that link

from entityframeworkcore.openedge.

EelhandsMcCoy avatar EelhandsMcCoy commented on June 14, 2024

Huh. I read that, but these tables have "keys" in that they have an index...but I suppose it's not actually unique. I'll add that to each of my models and see what happens, thank you.

from entityframeworkcore.openedge.

EelhandsMcCoy avatar EelhandsMcCoy commented on June 14, 2024

So I added:
[Key]
[Column("rowid")]
public string Rowid { get; set; }

to the model class but I did not modify the context to include this column. This is the modelbuilder's entity definition:

            modelBuilder.Entity<PromoTransHdr>(entity =>
            {
                entity.HasKey(e => new { e.ContractNo, e.ExpireDate });

                entity.ToTable("promo-trans-hdr");

                entity.Property(e => e.ContractNo)
                    .HasColumnName("contract-no")
                    .HasColumnType("character");

                entity.Property(e => e.ExpireDate)
                    .HasColumnName("expire-date")
                    .HasColumnType("date");

                entity.Property(e => e.BillingCode)
                    .HasColumnName("Billing-code")
                    .HasColumnType("character");

                entity.Property(e => e.Description)
                    .IsRequired()
                    .HasColumnName("description")
                    .HasColumnType("character");

                entity.Property(e => e.OrigAmt)
                    .HasColumnName("orig-amt")
                    .HasDefaultValueSql("0");

                entity.Property(e => e.OrigDate)
                    .HasColumnName("orig_date")
                    .HasColumnType("date");

                entity.Property(e => e.PromoId)
                    .HasColumnName("promo-id")
                    .HasDefaultValueSql("0");

                entity.Property(e => e.PromoTransno)
                    .HasColumnName("promo-transno")
                    .HasDefaultValueSql("0");

                entity.Property(e => e.Restricted)
                    .HasColumnName("restricted")
                    .HasColumnType("logical")
                    .HasDefaultValueSql("no");

                entity.Property(e => e.TransDate)
                    .HasColumnName("trans-date")
                    .HasColumnType("date");

                entity.Property(e => e.UsedAmt)
                    .HasColumnName("used-amt")
                    .HasDefaultValueSql("0");
            });

This did not solve the problem.

{
  "value": [
    {
      "rowid": "0000000000105448618",
      "promoId": 103,
      "transDate": "2015-11-30T00:00:00",
      "description": "WarrantyPayment:1170389",
      "contractNo": "Jeff",
      "expireDate": "2015-12-30T00:00:00",
      "origAmt": 6,
      "usedAmt": 6,
      "promoTransno": 137972,
      "billingCode": "GBB",
      "restricted": false,
      "origDate": null
    },
    {
      "rowid": "0000000000105448618",
      "promoId": 103,
      "transDate": "2015-11-30T00:00:00",
      "description": "WarrantyPayment:1170389",
      "contractNo": "Jeff",
      "expireDate": "2015-12-30T00:00:00",
      "origAmt": 6,
      "usedAmt": 6,
      "promoTransno": 137972,
      "billingCode": "GBB",
      "restricted": false,
      "origDate": null
    },
// Repeat dozens of these.
}

The "key" that EF has selected (ContractNo, ExpireDate) is actually pretty nonsensical. The key should be PromoTransno. That is also an index in the database, but it is the second index and is not marked as 'primary.'

I will try adding rowId to the modelBuilder and if that doesn't work I'll see if I can use the second index instead.

from entityframeworkcore.openedge.

EelhandsMcCoy avatar EelhandsMcCoy commented on June 14, 2024

Adding:

                entity.HasKey(e => e.RowId);

                entity.Property(e => e.RowId)
                    .HasColumnName("rowid");

And commenting out the bad primary index/"key" fixed the problem. Thanks a lot for your help!

from entityframeworkcore.openedge.

alexwiese avatar alexwiese commented on June 14, 2024

from entityframeworkcore.openedge.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.