MapsterMapper / Mapster

A fast, fun and stimulating object to object Mapper
MIT License
4.29k stars 327 forks source link

EntityFromContext EF Core - entities without primary key error #596

Open lucascaser opened 1 year ago

lucascaser commented 1 year ago

Hello,

I have a .NET core project that has database views mapped to the entity framework and these have the builder.HasNoKey(); configuration, as they are used only for queries. Besides, I'm using the EntityFromContext() method, but it wasn't handled in case the entity doesn't have a primary key. image It is possible to see that there was no treatment, if the .FindPrimaryKey() == null, generating the error of object reference not set to an instance of an object.

Therefore, I opened a PR dealing with this problem.