This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| dev:csharp [2023/06/08 01:16] – [entityframework (my beloved)] adam | dev:csharp [2025/12/05 08:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 15: | Line 15: | ||
| </ | </ | ||
| - | so you make an abstract class `MyAbstractClass` and derive from it. | + | so you make an abstract class '' |
| Line 78: | Line 78: | ||
| ======= entityframework (my beloved) ======= | ======= entityframework (my beloved) ======= | ||
| + | |||
| + | install in your dev env: | ||
| + | |||
| + | dotnet tool install --global dotnet-ef | ||
| install packages: | install packages: | ||
| - | * Microsoft.EntityFrameworkCore.Design | + | |
| - | * Npgsql.EntityFrameworkCore.PostgreSQL (or whatever you like) | + | * Npgsql.EntityFrameworkCore.PostgreSQL (or whatever you like) |
| + | |||
| + | dotnet-ef dbcontext scaffold " | ||
| migrations: | migrations: | ||
| - | | + | |
| - | dotnet ef database update --connection " | + | dotnet ef database update --connection " |
| + | |||
| + | ======= enum names ======= | ||
| + | |||
| + | forget " | ||
| + | |||
| + | make yourself this function: | ||
| + | <code csharp> | ||
| + | public static string GetDescription< | ||
| + | where T : struct | ||
| + | { | ||
| + | Type type = enumerationValue.GetType(); | ||
| + | if (!type.IsEnum) | ||
| + | { | ||
| + | throw new ArgumentException(" | ||
| + | } | ||
| + | |||
| + | //Tries to find a DescriptionAttribute for a potential friendly name | ||
| + | //for the enum | ||
| + | MemberInfo[] memberInfo = type.GetMember(enumerationValue.ToString()); | ||
| + | if (memberInfo != null && memberInfo.Length > 0) | ||
| + | { | ||
| + | object[] attrs = memberInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), | ||
| + | |||
| + | if (attrs != null && attrs.Length > 0) | ||
| + | { | ||
| + | //Pull out the description value | ||
| + | return ((DescriptionAttribute)attrs[0]).Description; | ||
| + | } | ||
| + | } | ||
| + | //If we have no description attribute, just return the ToString of the enum | ||
| + | return enumerationValue.ToString(); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | and then all you have to do is use '' | ||
| + | <code csharp> | ||
| + | private enum PublishStatusValue | ||
| + | { | ||
| + | [Description(" | ||
| + | NotCompleted, | ||
| + | Completed, | ||
| + | Error | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | ======= what is the actual publish command ======= | ||
| + | |||
| + | specify output folder. I don't know what all the other bullshit it insists on dumping in the folder is. | ||
| + | |||
| + | < | ||
| + | dotnet publish -c Release -o ../ | ||
| + | </ | ||
| + | |||
| + | also you can't not get '' | ||
| + | ======= why is asp.net not accepting my frombody thing? ======= | ||
| + | |||
| + | microsoft replaced the working json parser with one that doesn' | ||
| + | |||
| + | fix: | ||
| + | - '' | ||
| + | - go find where services are being added; '' | ||
| + | |||
| + | ======= which is a field, which is a property? ======= | ||
| + | |||
| + | <code csharp> | ||
| + | public class MyClass | ||
| + | { | ||
| + | // this is a field. | ||
| + | private string _myField; | ||
| + | |||
| + | // this is a property. When accessed it uses the underlying field, | ||
| + | // but only exposes the contract, which will not be affected by the underlying field | ||
| + | public string MyProperty | ||
| + | { | ||
| + | get | ||
| + | { | ||
| + | return _myField; | ||
| + | } | ||
| + | set | ||
| + | { | ||
| + | _myField = value; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | // This is an AutoProperty (C# 3.0 and higher) - which is a shorthand syntax | ||
| + | // used to generate a private field for you | ||
| + | public int AnotherProperty { get; set; } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | src: https:// | ||