-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added extension method for EF core #71
base: master
Are you sure you want to change the base?
Conversation
Extension method which dynamically registers the id conversion, and if needed automatically uses Identity
Hi @idan-h, thanks for this, I think people will find it very useful! Unfortunately, I don't think this is a great fit for the library itself - the StronglyTypedId library is a source generator only, so by default you don't want the dll copied to the build output, which means these methods aren't available 🤷 I think this is maybe better placed as a blog post/documentation in the README? |
Yea, this is why I added it in a seperate project, so it could be shipped in a different nuget package. If you want to add it to documentation thats fine by me, but I think in the long term there would be many more helper methods like this, so the real life integration would be feasible. You might want to consider adding another repo, or combine that in the current repo and ship different nuget package |
🤦♂️ My bad, I'm clearly tired, I read that as being src/StronglyTypedIds/Efcore. That makes much sense. I think you're probably right, as a separate package of "helpers" does make sense 🙂 My concern here is the heavy use of reflection to do this, which feels quite fragile. I'll have a little think about it and see |
Yea, that's true, but I think there is no way out of reflection on this one.. |
This seems very interesting. Could this be done as it's own nuget if it won't be merged in? Would also be useful to update the README.md when new functionality like this is introduced. |
Would it be possible have a source generator output a method with signature |
It looks like this method adds a configuration for ALL entities, ONLY on the For example, I have a class like public class SomeClass
{
public Guid Id { get; set; }
// this is a FK
public MyRelatedEntityClassId MyRelatedEntityClassId { get; set; }
public virtual MyRelatedEntityClass MyRelatedEntityClass { get; set; }
}
public class MyRelatedEntityClass
{
// this has 'many' of the 'someCLass'
public virtual ICollection<SomeClass> SomeClasses { get; set; }
}
if i register your class like: builder.RegisterStrongTypedIdDynamically(entityType, this, "MyStrongId "); I will get the error:
I'll make some modifications in the morning and share if i get it working. Or, i'll just manually register in the configs... |
#59
Extension method which dynamically registers the id conversion, and if needed automatically uses Identity
Use inside the DbContext
OnModelCreating
:Tested only with postgresql, tests with different dbs might be needed
It uses
And
If needed