在 T4 中,您可以使用“类功能”来包含您自己的自定义辅助函数等。像这样的东西:
<#+
public String ConvertToPascalCase(string allCaps){
CultureInfo cultureInfo = CultureInfo.InvariantCulture;
TextInfo textInfo = cultureInfo.TextInfo;
return textInfo.ToTitleCase(allCaps.ToLower()).Replace("_", "");
}
#>
并使用该辅助函数在 EF中创建您的自定义映射。
原答案:
使用TextInfo.ToTitleCase!
//your current culture
//CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
//or invariant culture, made no difference for me...
CultureInfo cultureInfo = CultureInfo.InvariantCulture;
TextInfo textInfo = cultureInfo.TextInfo;
string allCaps = "THIS_IS_ORACLE";
var result = textInfo.ToTitleCase(allCaps.ToLower()).Replace("_", "");
result.Dump();//tried it in LINQPad, result: "ThisIsOracle"