canton7 / Stylet

A very lightweight but powerful ViewModel-First MVVM framework for WPF for .NET Framework and .NET Core, inspired by Caliburn.Micro.
MIT License
995 stars 144 forks source link

EF Core and PropertyChangedBase #92

Closed mrlnnl closed 4 years ago

mrlnnl commented 4 years ago

I'm trying to build a netcore app using stylet, propertychanged.fody & entity framework core. While adding PropertyChangedBase as a base class on a model i get the following error:

Exception thrown: 'System.InvalidOperationException' in Microsoft.EntityFrameworkCore.dll An exception of type 'System.InvalidOperationException' occurred in Microsoft.EntityFrameworkCore.dll but was not handled in user code No suitable constructor found for entity type 'Action<Action>'. The following constructors had parameters that could not be bound to properties of the entity type: cannot bind 'object', 'method' in 'Action<Action>(object object, IntPtr method)'.

canton7 commented 4 years ago

In general, you're going to have a bad time if you try and use the same classes both as ViewModels and as EF models.

If your VMs are very simple, you can get away with binding directly to EF models (although you won't get INPC, of course). Anything more complex, and you're best off defining separate ViewModels and EF models, and mapping between them.

mrlnnl commented 4 years ago

Hello, thanks for your response. After months of working with ef core, you are definitely right in defining separate classes. ;)