2

I'm currently developing a WPF project which communicates with an ASP.NET Core Server application which is running on a Windows Server 2012 machine. To use my models in both classes I'm using a class library in the middle.

My current layout looks like this:

WPF - .NET 4.6
Class Library - PCL NetStandard1.3
WinForms Application - .NET4.6
ASP.NET Core - .NET4.6 

Everything works so far except using DataAnnotations within the PCL. I have defined my DbContext and my Identity Models inside the PCL too.

As longer I'm working on this project I think that this is the wrong layout for this. As soon as I'm using a classic class library I'm not able to add Identity.EntityFramework to the porject.

Can anybody give me a hint if there is a better solution for my project layout or I'm doing it the completely wrong way?

Thanks for any help!

UPDATE

Okay, I could get it to work. I accidentally used the Portable Class Library Template from Visual Studio. When I switched to Net Standard Library Template and just added the .Net 4.6 Framework DataAnnotations worked. To reference library from WPF and WinForms I had to reference directly to the dll because the project reference didn't work.

1 Answer 1

1

If I understand right your WPF application solely communicates with the ASP.NET Core application via some API, I guess.

That means you could just add the Database handling into the ASP.NET Core project (DbContext, etc.) and have the .NET Standard library solely to share models between the WPF and ASP.NET Core application.

Unfortunately I cannot say why DataAnnotations don't work for you. Could you specify if you're using Entity Framework or Entity Framework Core including the installed version?

In case of EF6 make sure you have a using directive for "System.ComponentModel.DataAnnotations" in the models.

Also it would be very useful if you could say which data annotations specifically you're trying to use and where/how it fails.

Sign up to request clarification or add additional context in comments.

1 Comment

MetaDataType didn't work because I could only reference to ComponentModel.Annotations. And MetadataType is not included there. Moving the DbContext into the Core project is not an option becaus my WinForms application is using it to0. And I need my Identity model inside the WPF application.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.