Answered by:
Custom Conventions in Entity Framework Database First

Question
-
User1271516709 posted
I know that we can create custom conventions in EF Code first using this.https://msdn.microsoft.com/en-us/data/dn469439.aspx
But is there any way I can apply same custom conventions in database first? I would like to apply a column renaming convention when I add new table to EF designer from the database.
Friday, October 9, 2015 12:15 AM
Answers
-
User-821857111 posted
You can modify the templates that generate the code files: https://msdn.microsoft.com/en-us/data/gg558520.aspx?f=255&MSPPError=-2147217396
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, October 9, 2015 2:07 AM
All replies
-
User-821857111 posted
You can modify the templates that generate the code files: https://msdn.microsoft.com/en-us/data/gg558520.aspx?f=255&MSPPError=-2147217396
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, October 9, 2015 2:07 AM -
User1271516709 posted
Hi Mike,
So i looked into it and it seems below code is generating my edmPropertyname.
public string Property(EdmProperty edmProperty) { return string.Format( CultureInfo.InvariantCulture, "{0} {1} {2} {{ {3}get; {4}set; }}", Accessibility.ForProperty(edmProperty), _typeMapper.GetTypeName(edmProperty.TypeUsage), _code.Escape(edmProperty), _code.SpaceAfter(Accessibility.ForGetter(edmProperty)), _code.SpaceAfter(Accessibility.ForSetter(edmProperty))); }
and it seems it using a method in CodeGenerationTools in another template.
<#@ include file="EF.Utility.CS.ttinclude"#>
is it possible that i can modify this template or add my own custom logic to this? if i change the original template "EF.Utility.CS.ttinclude" it will affect all the template which includes them right?
My main purpose is that when my columns has special characters in it it replaces them with _. rather than that i want to replace it with string.Empty.
With Regards,
Krunal Parekh
Friday, October 9, 2015 4:41 AM -
User-1858315090 posted
Hi,
From a support perspective this is really beyond what
we can do here in the forums. If you cannot determine your answer here or on
your own, consider opening a support case with us. Visit this link to see the
various support options that are available to better meet your needs: http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone.Friday, October 16, 2015 1:49 AM -
User1271516709 posted
OK. Thanks.
Friday, October 16, 2015 4:21 AM