Question Upgrading from ASP.NET Web API 2 to ASP.NET Web API Core 6

raysefo

Well-known member
Joined
Feb 22, 2019
Messages
361
Programming Experience
10+
Hello,

I have had this ASP.NET Web API application running smoothly for 2-3 years in a live environment. I used EF, generic repository, unit of work and unity dependency injection in this application. I want to upgrade my application to take advantage of Core 6.

How can I make this transition seamlessly? Can I have your recommendations?

Thank you.
 
Asp.net core web API supports DI as default right? So I don't need any third party framework like Unity. If so how can I manage this dependency below in the program.cs?

container.RegisterType<IGameServices, GameServices>().RegisterType<UnitOfWork>(new TransientLifetimeManager());
What I think of when someone says "unity" isn't what I think of when someone says "dependency injection/ioc container/framework" btw
 
I have no clue what The entity type 'List<string>' requires a primary key to be defined ??!
Do any of your tables have a string column that stores eg a CSV string, as a quick n dirty (emphasis on the dirty) way of having a 1:M relationship with multiple data items without hiving them off to a separate table?
 
Also, you might want to consider changing this structure - EF Core context embodies a unit of work, so having it again is unnecessary
 
The List<string> problem was due to this class. When I changed them to IList<string>, problem solved.

C#:
public class Coupon
    {
        [Key]
        public int Id { get; set; }
        public int ConfirmResponseID { get; set; }
        [NotMapped]
        public IList<string> serials { get; set; }
        [NotMapped]
        public IList<string> pins { get; set; }
        public virtual GameConfirmResponse confirmResponse { get; set; }
        public DateTime? expiryDate { get; set; }
        [NotMapped]
        public IList<string> StringsSerial
        {
            get { return serials; }
            set { serials = value; }
        }
        [NotMapped]
        public IList<string> StringsPin
        {
            get { return pins; }
            set { pins = value; }
        }

        [Required]
        public string Serial
        {
            get { return String.Join(",", serials); }
            set { serials = value.Split(',').ToList(); }
        }
        [Required]
        public string Pin
        {
            get { return String.Join(",", pins); }
            set { pins = value.Split(',').ToList(); }
        }
    }
 
So, you know when I said "do you have any tables that have a CSV in their columns" and you said "No"...
 
Back
Top Bottom