Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EF Core and Database First: cannot convert error #602

Closed
spetikala opened this issue Apr 20, 2020 · 2 comments
Closed

EF Core and Database First: cannot convert error #602

spetikala opened this issue Apr 20, 2020 · 2 comments
Assignees

Comments

@spetikala
Copy link

spetikala commented Apr 20, 2020

Description

Based on this documentation I am trying to implement AutoSave audit logging with database-first approach using Entity Framework Core plus audit.

However on the last line (in AddRange) in below code I get an error (see Exception):

static EntityContext()
{
      AuditManager.DefaultConfiguration.AutoSavePreAction = (context, audit) =>
         (context as EntityContext).AuditEntries.AddRange(audit.Entries);
}

Exception

cannot convert from 'System.Collections.Generic.IEnumerable<Z.EntityFramework.Plus.AuditEntry>' to 'MyProject.MyDataModels.AuditEntries'

Also note that I changed these marked lines:
grafik

Fiddle or Project

Fiddle: based on the default DB first fiddle I created this fiddle which produces the same error.

I also created a test project with code first and sqlite connection where everything works fine. Then from those entities I scaffolded the db and get above error.

I uploaded my test project here

Further technical details

  • EF version: latest
  • EF Plus version: latest
  • Database Provider: SQL Server and sqlite

Hope you can help figure out what I am doing wrong.

@JonathanMagnan JonathanMagnan self-assigned this Apr 20, 2020
@JonathanMagnan
Copy link
Member

Hello @thorstenschroeder ,

The issue happens because your Import should return a DbAuditEntry and DbAuditEntryProperty type. You currently return the wrong entity type which leads to this error.

Best Regards,

Jon


Performance Libraries
context.BulkInsert(list, options => options.BatchSize = 1000);
Entity Framework ExtensionsEntity Framework ClassicBulk OperationsDapper Plus

Runtime Evaluation
Eval.Execute("x + y", new {x = 1, y = 2}); // return 3
C# Eval FunctionSQL Eval Function

@spetikala
Copy link
Author

Thanks, I did have the wrong return type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants