{sus}
{sus}
CC#
Created by {sus} on 10/17/2024 in #help
Setting a Default Value for Migrations
I have a relationship between two models but the relationship is not required, i.e. the first model which "belongs to" the other model can exists on its own.
class Item {

[DefaultValue(0)]
public int? OwnerId {get;set;}

public Owner Owner { get;set; }
}

class Owner {
...
}
class Item {

[DefaultValue(0)]
public int? OwnerId {get;set;}

public Owner Owner { get;set; }
}

class Owner {
...
}
So in essence, class Item can stand on its own but it can also belong to someone. I am getting this when trying to run the database update command for the seed data which has set the OwnerId to 0 The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Items_Owners_OwnerId". The conflict occurred in database "<DB>", table "dbo.Owners", column 'Id'.
54 replies
CC#
Created by {sus} on 10/10/2024 in #help
✅ Migration-independent Database Seeding
Curious if EF has some sort of independent database seeding potential? I am kinda hoping to see a similar functionality to Laravel's Database Seeder where you can write the seed in a file which you can run at any time, regardless of whether or not your migrations are already ran. I find the HasData fucntiuonality inherently counterproductive as I don't want to re-run all migrations over and over just so I can work with my seed data. Laravel Seeding: https://laravel.com/docs/11.x/seeding
86 replies
CC#
Created by {sus} on 7/30/2024 in #help
Making a List<T> from an instance of T without knowing T
Is that possible? The idea is to make a List of T if the the object in question is T
53 replies