Issue when calling IRepository<>.Update()
See original GitHub issueHi,
Using ABP 0.7.7, Entity Framework 6.1.3,
I am getting the following exception when I am updating a record that already exists in the destination table:
My table is defined as follows:
CREATE TABLE [Platform].[ChangeLog](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Date] [Date] NOT NULL,
[DeveloperInitials] [nvarchar](3) NOT NULL,
[Entry] [nvarchar](max) NOT NULL,
[FogBugReference] [int] NOT NULL,
[Guid] [nvarchar](36) NOT NULL,
[IntendedAudience] [int] NOT NULL,
[Version] [nvarchar](15) NOT NULL,
[WebsitePropertyId] [smallint] NOT NULL,
CONSTRAINT [PK_ChangeLog] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [Platform].[ChangeLog] WITH CHECK ADD CONSTRAINT [FK_ChangeLog_WebsitePropertys] FOREIGN KEY([WebsitePropertyId])
REFERENCES [Reference].[WebsitePropertys] ([WebsitePropertyID])
GO
ALTER TABLE [Platform].[ChangeLog] CHECK CONSTRAINT [FK_ChangeLog_WebsitePropertys]
GO
and has the following records in it at time of calling the method:
As you can see the Id value is 6 that I am supplying to the call to the repository method _PlatformChangeLogRepository.Update(). So what I am trying to work out is why I am getting the exception here. Is it how I am calling ABP or something else?
Below are the relevant class declarations for the various classes referenced above.
//ABP Repository class
public interface IOzCpPlatformChangeLogRepository : IRepository<Platform_ChangeLogModel>
{
}
//EF model class
public class Platform_ChangeLogModel : OzEfEntity, IEntity
{
public int Id { get; set; } // Id (Primary key)
public DateTime Date { get; set; } // Date
public string DeveloperInitials { get; set; } // DeveloperInitials
public string Entry { get; set; } // Entry
public int FogBugReference { get; set; } // FogBugReference
public string Guid { get; set; } // Guid
public int IntendedAudience { get; set; } // IntendedAudience
public string Version { get; set; } // Version
public short WebsitePropertyId { get; set; } // WebsitePropertyId
// Foreign keys
//**public virtual Reference_WebsitePropertysModel Reference_WebsitePropertysModel { get; set; } // FK_ChangeLogs_WebsitePropertys
/// <summary>
/// Checks if this entity is transient (not persisted to database and it has not an
/// <see cref="P:Abp.Domain.Entities.IEntity`1.Id" />).
/// </summary>
/// <returns>
/// True, if this entity is transient
/// </returns>
public bool IsTransient()
{
return false;
}
}
//EF configuration class
public class Platform_ChangeLogConfiguration : EntityTypeConfiguration<Platform_ChangeLogModel>
{
public Platform_ChangeLogConfiguration(string schema = "Platform")
{
ToTable(schema + ".ChangeLog");
HasKey(x => x.Id);
Property(x => x.Id).HasColumnName("Id").IsRequired().HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
Property(x => x.Date).HasColumnName("Date").IsRequired();
Property(x => x.DeveloperInitials).HasColumnName("DeveloperInitials").IsRequired().HasMaxLength(3);
Property(x => x.Entry).HasColumnName("Entry").IsRequired();
Property(x => x.FogBugReference).HasColumnName("FogBugReference").IsRequired();
Property(x => x.IntendedAudience).HasColumnName("IntendedAudience").IsRequired();
Property(x => x.Guid).HasColumnName("Guid").IsRequired().HasMaxLength(36);
Property(x => x.Version).HasColumnName("Version").IsRequired().HasMaxLength(15);
Property(x => x.WebsitePropertyId).HasColumnName("WebsitePropertyId").IsRequired();
// Foreign keys
//***HasRequired(a => a.Reference_WebsitePropertysModel).WithMany(b => b Platform_ChangeLogModel).HasForeignKey(c => c.WebsitePropertyId); // FK_ChangeLogs_WebsitePropertys
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:19 (12 by maintainers)
Top Results From Across the Web
Jpa Repository save() doesn't update existing data
I am trying to update data and as I know save() method saves entity if the id is null or update an existing...
Read more >repository.save() does not update the returned entity when ...
Unfortunately, when I call repository.save() to update an existing entity the object returned does not have the createdBy and createdDate ...
Read more >Partial Data Update With Spring Data
In this tutorial, we will cover techniques and approaches to performing a partial instead of a full update. 2. Problem. As stated before,...
Read more >The best Spring Data JpaRepository
In this article, I'm going to show you the best way to use the Spring Data JpaRepository, which, most often, is used the...
Read more >How to update an entity using Spring Data JPA
Spring Data JPA provides save() method to update the entity. ... Calling repository method to update entity using @Modifying.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Also, as I see you did not set Date property which is NOT NULL in the database.
Ok. I found the problem. It’s about my codes. But why error throwed i could not understood.
I used this codes to get images of Listing.
This code pieces runs these codes in service layer
ListingDto is here.
So, i created a new Service method.
With this changes the Update medthod above runs well now.
And the Action Medthod here you may want to investigate.
Not: In the GetUserListingById medthod i mapped Listing to ListingDto even listing returns null by mistakely.
i removed the line
output.Listing = listing.MapTo<ListingDto>();
in else block and tried to run codes before changes to understand if this line causes error. No, same error occured.