Posts

Showing posts with the label entity-framework-core

IQueryable to return a single record

IQueryable<T> to return a single record I am using EF Core and am attempting to create a query provider which accepts any type and a single value. I then want to run a query to return the FirstOrDefault of the passed in items which have the selected property set to the passed in value. something similar to this: public class TagPicker<T> { public IQueryable<T> Pick(IQueryable<T> source, string collumn, string filter) { T result = source.FirstOrDefault(r => r.collumn == value); if (result is null) { return new T { collumn = filter }; } else { return result; } } } I have several types which will need this type of query performed. I am trying to avoid having to create duplicates of this type of query for each type. Any Ideas? What problem are you trying to solve with this code? This looks like an attempt to replicate Where() or FirstOrDefault(predicat...

EF Core + npgsql DateTime uses windows 10 localization for formatting

EF Core + npgsql DateTime uses windows 10 localization for formatting I updated my development machine to Windows 10 and tried to add a new Required DateTime property to a class. I created the migration with Add-Migration and a reasonable migration was generated: { migrationBuilder.AddColumn<DateTime>( name: "AskingTime", table: "Questions", nullable: false, defaultValue: new DateTime(2000, 1, 1, 15, 0, 0, 0, DateTimeKind.Unspecified)); } I tried to apply it with Script-Migration, but it fails with this error: ALTER TABLE "Questions" ADD "AskingTime" timestamp without time zone NOT NULL DEFAULT TIMESTAMP '2000-01-01 15.00.00'; Npgsql.PostgresException (0x80004005): 22007: invalid input syntax for type timestamp: "2000-01-01 15.00.00" We tried this with my coworkers machine which still has Windows 7 and it works as expected without errors. The problem was that ...