SteveDunn / Vogen

A semi-opinionated library which is a source generator and a code analyser. It Source generates Value Objects
Apache License 2.0
781 stars 45 forks source link

EFCore 8.1 not supported #557

Closed arteny closed 7 months ago

arteny commented 7 months ago

Describe the bug

In main readme doc it is written that using structs no needs additional actions and works as is, but not working on my side with following error message: Unable to create a 'DbContext' of type ''. The exception 'The property 'Market.Id' could not be mapped because it is of type 'MarketId', which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

full doc for EFCore https://stevedunn.github.io/Vogen/value-objects-in-efcore.html is not available if i switch it to class and using this type:

[ValueObject(typeof(string), conversions: Conversions.EfCoreValueConverter)]
public partial class EventId
{..

then another error is returned: Unable to create a 'DbContext' of type ''. The exception 'The entity type 'Event' requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. For more information on keyless entity types, see https://go.microsoft.com/fwlink/?linkid=2141943.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728 when key is defined:

    public class Event
    {
        [Key]
        public required EventId Id { get; set; }

Steps to reproduce

add-migration

Expected behaviour

No error

arteny commented 7 months ago

OK, I found finally how to make it working. For structs I also need to specify conversions parameter [ValueObject<string>(conversions: Conversions.EfCoreValueConverter)] and add mapping for this property

ronnieoverby commented 5 months ago

This goes against the documentation, which states that for structs there's nothing to do.

SteveDunn commented 4 months ago

I think the documentation might be incorrect. Whether a struct or class, EFCore still needs help in creating it.

ronnieoverby commented 4 months ago

I created PR #569