User Tools

Site Tools


dev:csharp

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
dev:csharp [2023/06/19 18:56] adamdev:csharp [2024/12/08 03:53] (current) – [entityframework (my beloved)] adam
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 +  * Microsoft.EntityFrameworkCore.Design 
-* Npgsql.EntityFrameworkCore.PostgreSQL (or whatever you like)+  * Npgsql.EntityFrameworkCore.PostgreSQL (or whatever you like) 
 + 
 +  dotnet-ef dbcontext scaffold "Host=HOST;Database=DBNAME;Username=USERNAMEPassword=PASSWORD;IncludeErrorDetail=true;" Npgsql.EntityFrameworkCore.PostgreSQL 
  
 migrations: migrations:
-    dotnet ef migrations add "name of migration" +  dotnet ef migrations add "name of migration" 
-    dotnet ef database update --connection "Host=asdfasdfasdf etc" +  dotnet ef database update --connection "Host=asdfasdfasdf etc" 
-    +
 ======= enum names ======= ======= enum names =======
  
Line 131: Line 138:
 </code> </code>
  
 +======= 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.
 +
 +<code>
 +dotnet publish -c Release -o ../publish
 +</code>
 +
 +also you can't not get ''appsettings.Development.json'' to show up in release. your only option is to delete it manually.
 +======= why is asp.net not accepting my frombody thing? =======
 +
 +microsoft replaced the working json parser with one that doesn't. https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-apis/
 +
 +fix: 
 +  - ''dotnet add package Microsoft.AspNetCore.Mvc.NewtonsoftJson --version [compatible version]''
 +  - go find where services are being added; ''services.AddControllers().AddNewtonsoftJson();''. (hint: Builder.Services?)
 +
 +======= which is a field, which is a property? =======
 +
 +<code csharp>
 +public class MyClass
 +{
 +    // this is a field.  It is private to your class and stores the actual data.
 +    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; } 
 +}
 +</code>
 +
 +src: https://stackoverflow.com/a/295109/1173856
dev/csharp.1687201013.txt.gz · Last modified: 2023/06/19 18:56 by adam