Closed MarkLFT closed 1 year ago
After I stopped looking for the solution to this, I found the answer. A simple ""{{NameHumanCase}}"" was the answer. And it works great.
I haven't closed this, as I am hoping you will consider adding this to the base templates so it is available as standard. ;-)
Again many thanks for a great product, and sorry for posting so many questions.
The Field property, is that how its named in the C# class, or how it is named in the database?
i.e. it could be named is_allowed
in the database, and IsAllowed
in the C# class.
Could you give me an example of where you would find this useful?
What I have done is in the ttinclude added the following line:
public const string {{NameHumanCase}}Field = ""{{NameHumanCase}}""; {{#newline}}
This is inserted directly below the row that defines th Poco class properties. The result is I get the extra lines in the PoCO class as follows
public string Code { get; set; }
public const string CodeField = "Code";
public string IsoCode { get; set; }
public const string IsoCodeField = "IsoCode";
The purpose behind this is, in my code, it is often necessary for me to define the column I am referring to. Without these const strings I would be forced to use magic strings i.e. column["Code"] instead of column[TableName.CodeField].
These types of references are used a lot in Infragistics and Syncfusion, plus others, controls to define from the datasource which columns to bind for the display/value properties. In our Cashier program, we have over 300 such binding references. I would hate to think how many there will be in our main hotel system application, certainly well into the thousands.
I am sure there will be other ways this can be achieved, but in my experience, this is by far the most performant.
Thanks Mark. I'll add it as a boolean option in the .tt file to include them or not :-)
Many thanks, greatly appreciated.
Did you get a chance to add this boolean option in version 3.6? I have taken a look but cannot seem to find it.
Great thanks
Hi Simon,
I was wondering if you ever got around to this? I am currently updating our data classes to .Net 7 EF Core 7, and using the new 3.8 templates, but it is a bit of a pain as I must remember to re-add my workarounds.
This has now been added, and will be in the next release.
The new settings flag is called Settings.IncludeFieldNameConstants
Settings this to true will return a class with properties like:
public int Id { get; set; } // ID (Primary key)
public const string IdField = "Id";
public int OrderId { get; set; } // OrderID
public const string OrderIdField = "OrderId";
public string Sku { get; set; } // sku (length: 15)
public const string SkuField = "Sku";
This has been released in v3.8.2. Any problems, please let me know.
I am trying to add a const string with the field name of each field to allow the use of strongly typed field names instead of magic strings. Our previous ORM created these automatically and they are very useful. For example:
To achieve this here I tried adding the following to the ttinclude file
The problem I have is the double quotes around the fieldname in the second line. (The first line is shown to show location only) I have tried """, I have tried /", I have tried '/"', and after dozens of hours of searching, and trial and error, I am unable to find the correct way to do this. Can you please help.
The addition of this line might also be helpful for others to avoid the use of magic strings.
Thanks for any advise you can give,