AlisterKB
creating migrations on an existing DB to add a column(efcore)
so I have a webapi project, dotnet 8 efcore 8 and postgres
project was DB first and hence scaffolded. now I wanna add a property to an entity of mine AND/OR add a column to a table
I have always done db first and never done code first and have never touched migrations. tried adding migration but doing so it wants to create all tables with updated columns. tables already exist and have data I'd rather not lose (though it wouldn't be end of the world as it is a personal project for learning) so wondering how can I add a column without dropping my tables and not updating my table with sql command scaffolding it again. Most resources I've found involve somewhat hacky way of adding migration and deleting the content in up and down methods in migration though I don't understand how that might help ?
31 replies
Hangfire implementation in Repository pattern
Hi, sorry for newbie question.
I am trying to add hangfire to my project. I believe I am using DDD to the best of my ability
trying to incorporate hangfire and follow DDD architecture i've hit a snag.
here is some code snippet from my hangfire implementation in each layer:
https://paste.mod.gg/ynibbxjvpvfc/0
and below is my project structure:
├───App.Presentation
│ ├───Controllers
│ └───Properties
├───App.Application
│ └───Services
├───App.Domain
│ └───Aggregates (or I believe more commonly people call them entities)
├───App.Infrastructure
│ └───Persistence
│ └───Repositories
└──
I've only installed hangfire related packages in infrustructure layer (Hangfire.AspNetCore & Hangfire.PostgreSql)
due to doing so I only have access to the hangfire methods in infrustructure. now when I wanna use/implement in application layer
RecurringJob.AddOrUpdate(string, Expression<Action>,CRONEXPRESSION)
I pass my JobService a string and I cannot utilize the hangfire method Corn.daily() or other methods provided by hangfire itself.
I really could use your help to know whether I should install hangfire.AspNetCore in application ? and remove it from infrastructure and leave the Hangfire.PostgreSql in infrustructure or what.
really appreciate your kind assistance on this. please let me know if I should provide you with more details.
I would also be very thankful if you could direct me to a code example of hangfire implementation in DDD and Repository pattern.
cheers
8 replies
hangfire in DDD
hi good folks,
I have only given a try to hangfire yesterday.
built a simple api project and jammed everything in one layer(added my background tasks in program.cs) just to see what can be done with it and to test the waters.
now I wanna incorporate it my existing project which follows DDD architecture(mono). but I'm confused as to where to put what and what layer do I install what?
1 replies
casting required for nullable even after checking for null
would truly appreciate your hep with below 🙏
public class SomeClass
{
public DateTime? Lastupdated { get; set; } public static explicit operator Payment(AddPaymentDTO source) => new Payment() {
Lastupdated = source.Lastupdated is not null? source.Lastupdated : DateTime.Now.ToUniversalTime(), }; } if I write my casting like above I get the error Cannot implicitly convert type 'System.DateTime?' to 'System.DateTime'. An explicit conversion exists (are you missing a cast?) but if I do like below the its fine with it Lastupdated = source.Lastupdated is not null? (DateTime)source.Lastupdated : DateTime.Now.ToUniversalTime() why is the compiler still bother about it being nullable since I've already checked for it not being null ? is this the right way to go about it ? or is there a better way?
public DateTime? Lastupdated { get; set; } public static explicit operator Payment(AddPaymentDTO source) => new Payment() {
Lastupdated = source.Lastupdated is not null? source.Lastupdated : DateTime.Now.ToUniversalTime(), }; } if I write my casting like above I get the error Cannot implicitly convert type 'System.DateTime?' to 'System.DateTime'. An explicit conversion exists (are you missing a cast?) but if I do like below the its fine with it Lastupdated = source.Lastupdated is not null? (DateTime)source.Lastupdated : DateTime.Now.ToUniversalTime() why is the compiler still bother about it being nullable since I've already checked for it not being null ? is this the right way to go about it ? or is there a better way?
15 replies