andrewlock / StronglyTypedId

A Rosyln-powered generator for strongly-typed IDs
MIT License
1.52k stars 79 forks source link

Nested StronglyTypedId 1.0.0-beta02 #40

Closed patrolez closed 2 years ago

patrolez commented 2 years ago

Hello @andrewlock, I am migrating from 0.2.1 to 1.0.0-beta02 and I have noticed that nesting:

public partial class Blog
{
  [StronglyTypedId(backingType: StronglyTypedIdBackingType.String, converters: StronglyTypedIdConverter.NewtonsoftJson | StronglyTypedIdConverter.SystemTextJson | StronglyTypedIdConverter.EfCoreValueConverter)]
  public partial struct PostId { }
}

Stopped triggering code generation, so calling a constructor is not possible and dotnet sdk 5.0.402 returns: error CS1729: 'Blog.PostId' does not contain a constructor that takes 1 arguments

While it was working for 0.2.1. For now, I have just moved PostId outside to be directly under namespace scope and prefixed its name, then done some Find&Replace action.

andrewlock commented 2 years ago

Hi @patrolez, apologies, the source generator version doesn't support nested structs yet, but thanks for flagging it!

patrolez commented 2 years ago

Hello @andrewlock, I've just read through the entire README file and this limitation is highlighted, so there is nothing to apologize about :+1:

Could it be also included within a list about breaking changes related to description which could be helpful regarding migration from 0.2 to 1.x?

I can see that there are two files with such a list: https://github.com/andrewlock/StronglyTypedId/blob/master/CHANGELOG.md https://github.com/andrewlock/StronglyTypedId/blob/master/releasenotes.props

Btw. https://andrewlock.net/strongly-typed-ids-in-ef-core-using-strongly-typed-entity-ids-to-avoid-primitive-obsession-part-4/#creating-a-custom-valueconverterselector-for-strongly-typed-ids is great, and I think it could be also referred somewhere within repository OR the Readme file.

andrewlock commented 2 years ago

Hey @patrolez , thanks for trying it out! The nested id issue is a limitation I intend to fix soon. Thanks for the suggestions about extra docs, I'll add those too!

Note that for beta3 and onwards you will need to use the .net 6 SDK as the source generator uses a more efficient mechanism now