Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate all Entity Framework classes with Pascal Case notation on properties?

I have an Oracle database that has columns named in the following way : CREATED_BY, EMPLOYEE_FIRST_NAME,

When my Entity Framework classes are generated, I want the column's associated properties to look like : CreatedBy, EmployeeFirstName, etc...

Is there a way to do it without having to go edit every property manually ?

like image 399
Attilah Avatar asked Oct 04 '22 15:10

Attilah


1 Answers

It actually might not be about C# code at all. If you are using Oracle then I assume it is either ModelFirst or DatabaseFirst approach. In this case the code is generated based on the CSDL. If you convert property names stuff will break since EF will not be able to find types and properties that correspond to the property names in the CSDL. In addition to that as soon as the code will be regenerated (e.g. you save your model) you will lose all your changes. What you need to do is to change the names of the properties in the CSDL (the conceptual part of the EDMX) and then MSL (the mapping part of EDMX) accordingly. So you are looking actually at processing Xml. I think it can be done relatively easily with Xslt or Linq to Xml if you are familiar with these technologies. If you do this correctly the code generator/T4 template should generate code with the names you provided. Alternatively, you can change names in the EF designer manually but it will be a lot of work.

like image 149
Pawel Avatar answered Oct 13 '22 10:10

Pawel