-
-
Notifications
You must be signed in to change notification settings - Fork 298
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
Possibility to introduce templating for on-model-creating method #20
Comments
PRs are very welcome - does this work for you as desired? |
Looks like it is related to ErikEJ/SqlCeToolbox#683 |
From @mbharodia on April 12, 2018 15:26 Hi Eric: The tool you have developed is really useful. Earlier I used POCO generator for EF 6 and I had an opportunity to extend the context class using partial methods. I have come across many occasions, when I needed to extend the partial context class generated by the tool due to the legacy databases were not designed to support domain driven development; for example, missing Primary Key and Foreign Key did not enable the tool to generate required relationships between parent and child objects. This can be easily fixed if there is an opportunity to extend this context class by manually writing some code using fluent APIs. Thanks, and have a good day! Regards, PRs are very welcome - does this work for you as desired? — |
I will try to simply always add the two extra lines:
and
|
From @mbharodia on April 15, 2018 20:15 Okay. Thanks a lot for your help! From: Erik Ejlskov Jensen [mailto:notifications@github.com] I will try to simply always add the two extra lines: OnModelCreatingPartial(modelBuilder); and partial void OnModelCreatingPartial(ModelBuilder modelBuilder); — |
@mbharodia Fixed in latest daily build (no Handlebars required) |
From @mbharodia on April 28, 2018 13:12 Thank you so much Erik! From: Erik Ejlskov Jensen notifications@github.com @mbharodiahttps://github.com/mbharodia Fixed in latest daily build (no Handlebars required) — |
Please let me know if it solves your issue! |
From @mbharodia on April 30, 2018 17:54 Hi Erik: It looks like that it is not working as per the expectation. When I got the latest daily build, it generated the following code.
I think that the correct code should be like the following. Please pay attention to "OnModelCreatingPartial" at two different places below.
Additionally, handlebar setup stopped working. I know that you have mentioned that this build is for "no handlebar" support. I guess it is still good to have handlebar to do some customization if needed. The above explanation may not make sense if I have missed anything that you wanted me to look into before running the templates for your latest daily build. Please let me know your feedback. |
Hmmm... Tried a diferent approach in the latest build |
@mbharodia I have attempted a fix in the latest daily build, would be grateful if you could try it out |
@mbharodia ping? |
Hi Erick. That worked well! Thank you. I am not sure whether it is a lot to ask further, however, is it possible to do the same with POCO classes?
Additionally, I don't see handle bar support. Earlier it was easier for me to add extra Using statements to classes generated. I create POCO classes and DbContext in a separate project and Using Statement is needed in DbContext so that it can reference the project with POCO classes. I am wondering whether handle bar support is going be supported or not. However, I really appreciate your help with the above. |
@mbharodia The poco classes are already partial, and OnMoldeCreating does not make any sense here. The Handlebars feature is temporarily disabled, see #12 |
@mbharodia Handlebars are back in latest daily build |
From @mbharodia on April 12, 2018 13:46
Here is handle bar template for DbContext
{{> dbimports}}
namespace {{namespace}}
{
public partial class {{class}} : DbContext
{
{{> dbsets}}
{{#if entity-type-errors}}
{{#each entity-type-errors}}
{{spaces 8}}{{{entity-type-error}}}
{{/each}}
{{/if}}
{{{on-configuring}}}
{{{on-model-creating}}}
}
}
on-model-creating injects
protected override void OnModelCreating(ModelBuilder modelBuilder)
I like to do the following
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
}
The way template has been designed right now, I am not able to inject the following (or I may not know)
OnModelCreatingPartial(modelBuilder)
Here is my updated template to introduce partial method
{{> dbimports}}
namespace {{namespace}}
{
public partial class {{class}} : DbContext
{
{{> dbsets}}
{{#if entity-type-errors}}
{{#each entity-type-errors}}
{{spaces 8}}{{{entity-type-error}}}
{{/each}}
{{/if}}
{{{on-configuring}}}
{{{on-model-creating}}}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
}
As DbContext is partial class already, I can have another partial class and add required code as per my requirements. I think this provides me an easier way to extend the functionality using PARTIAL setup.
I think the above is already available in EF6 POCO Generated and it has been useful to me in many instances. I am just wondering whether there is any possibility of doing the same thing.
I highly appreciate your recommendation or feedback or any help in this regard
Copied from original issue: ErikEJ/SqlCeToolbox#695
The text was updated successfully, but these errors were encountered: