none
.Net Framework 4.61 (EF 6.0); POCO models in .NET standard project causes: One or more validation errors were detected during model generation: EntityType '<entity_name>' has no key defined. Define the key for this EntityType. RRS feed

  • General discussion

  • Hello,

    I have two projects, one in .NET Framework 4.61 (prj1) and second in .NET Core 2.2 (prj2) which both uses the same database. BTW, the reason is that Azure Cloud Services supports only .NET Framework. Because POCO model classes are the same for both project, I placed them in the other project in .NET Standard 2.0 (prjShared). prjShared is referenced from both prj1 and prj2 and all is good (compile, run).

    In prj1 EF 6.0 is used. In prj2 EF Core is used. Thats obvious.

    But when i run prj1, first use of DbSet in DbContext results in exception:

    Exception message: One or more validation errors were detected during model generation: UriahIotConsumerDAL.SqlData.ChannelNumber: : EntityType 'ChannelNumber' has no key defined. Define the key for this EntityType........

    When I exclude prjShared from prj1 and link all files with POCO models directly into prj1 (Add file as link) then everything works fine.

    Using linked files is the hell for future in large project. Have you anybody out three encountered with this trouble? Do you know some solution/workaround?


    Thursday, October 24, 2019 2:13 PM

All replies

  • Hi Jindrich Pastorek,

    Thank you for your sharing.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, October 25, 2019 9:38 AM
    Moderator
  • Finally I had to use linked linked files. I found out that the problem was with attributes ([Key], ...). Simply it is not possible to share two project with different EF (EF .net 6.2, EF CORE) in one application. This is my opinion.

    If that project will contain absolutely POCO classes, with no EF core atributes and no using (using System.ComponentModel.DataAnnotations.Schema;, etc) then it will be possible. So in this case I can say that using fluent api for definig keys, indexes, ... is good

    Thursday, November 7, 2019 1:09 PM