Is first letter capitalization in entity framework models the proper way?
The first two are properties, so they should start with a capital letter, that is called Pascal Case.
Check this link for Capitalization Conventions
Also, if you want to keep your tables and column names with lowercase first letter, EF 6 introduces a new feature called Custom Conventions, so there's no need to add Table
attribute to all you classes.
Check this Answer that explains how to set up a "first letter lowecase convention".
Changing default column name for navigation property
Try using MapKey():
modelBuilder.Entity<TreeItem>()
.HasRequired(it => it.Tree)
.WithMany()
.Map(m => m.MapKey("tree_id"));
EDIT
For EF Core, you might have to use a work around as mentioned here:
modelBuilder.Entity<TreeItem>()
.Property<long>("TreeId")
.HasColumnName("tree_id");
Lower-casing the query generated by Entity Framework
I have never tried this but it looks promising for your case and i happen to be outside watching the maple leafs right now. EF allows interception so you can intercept the query and perhaps call ToLower()
on the command.CommandText
:
class EFCommandInterceptor: IDbCommandInterceptor
{
public void NonQueryExecuted(System.Data.Common.DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
LogInfo("NonQueryExecuted", String.Format(" IsAsync: {0}, Command Text: {1}", interceptionContext.IsAsync, command.CommandText));
}
public void NonQueryExecuting(System.Data.Common.DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
LogInfo("NonQueryExecuting", String.Format(" IsAsync: {0}, Command Text: {1}", interceptionContext.IsAsync, command.CommandText));
}
public void ReaderExecuted(System.Data.Common.DbCommand command, DbCommandInterceptionContextt<System.Data.Common.DbDataReader> interceptionContext)
{
LogInfo("ReaderExecuted", String.Format(" IsAsync: {0}, Command Text: {1}", interceptionContext.IsAsync, command.CommandText));
}
public void ReaderExecuting(System.Data.Common.DbCommand command, DbCommandInterceptionContext<System.Data.Common.DbDataReader> interceptionContext)
{
LogInfo("ReaderExecuting", String.Format(" IsAsync: {0}, Command Text: {1}", interceptionContext.IsAsync, command.CommandText));
}
public void ScalarExecuted(System.Data.Common.DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
{
LogInfo("ScalarExecuted", String.Format(" IsAsync: {0}, Command Text: {1}", interceptionContext.IsAsync, command.CommandText));
}
public void ScalarExecuting(System.Data.Common.DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
{
LogInfo("ScalarExecuting", String.Format(" IsAsync: {0}, Command Text: {1}", interceptionContext.IsAsync, command.CommandText));
}
private void LogInfo(string command, string commandText)
{
Console.WriteLine("Intercepted on: {0} :- {1} ", command, commandText);
}
}
You can read more here.
API Json response to C# Object with capital case properties first letter
By default, ASP.NET Core encodes all JSON properties names in camel case, to match JSON conventions (see the announcement of the change on GitHub).
If you want to keep the C# conventions, you need to change the default JSON serializer.
In your Startup.cs
, configure the MVC part like this (ASP.Net Core 3.0):
services
.AddMvc()
.AddNewtonsoftJson(options =>
{
// don't serialize with CamelCase (see https://github.com/aspnet/Announcements/issues/194)
jsonSettings.ContractResolver = new JsonContractResolver();
});
For ASP.NET Core 2.0 :
services
.AddMvc()
.AddJsonOptions(options =>
{
// don't serialize with CamelCase (see https://github.com/aspnet/Announcements/issues/194)
jsonSettings.ContractResolver = new DefaultContractResolver();
});
Related Topics
Returning a String from Pinvoke
How to Set PDF Paragraph or Font Line-Height with Itextsharp
Navigation Property Without Declaring Foreign Key
Incorrect Syntax Near the Keyword 'User'
SQL Server Blocked Access to Procedure 'Sys.Sp_Oacreate' of Component 'Ole Automation Procedures'
Mvc-Web API: 405 Method Not Allowed
Visual Studio 2012 Conditional Bundling
Linux to Windows Bad Encoding Response
How to Install Python for .Net on Windows
Hmc Sha1 Hash - C# Producing Different Hash Output Than Ruby
How to Prevent or Block Closing a Winforms Window
How to Prevent Xss (Cross Site Scripting) Whilst Allowing HTML Input
Difference Between SQLdatareader.Read and SQLdatareader.Nextresult
How to Pass Variable into SQLcommand Statement and Insert into Database Table
How Get List of Local Network Computers
Scraping Data Dynamically Generated by JavaScript in HTML Document Using C#