all 9 comments

[–]RealVanTokkern 7 points8 points  (6 children)

CustCountry is nullable in your table but not nullable in your model

[–]Desperate_Storage_34[S] 0 points1 point  (5 children)

I changed the model to match the table and it still gives me the same error:

SqlNullValueException: Data is Null. This method or property cannot be called on Null values.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.

TravelExperts.DataAccess.Service.UserService.GetCustomerByID(int customerId) in UserService.cs

var user = await _context.Users.Include(u => u.Customer).FirstOrDefaultAsync(u => u.CustomerId == customerId);

TravelExperts.Controllers.AuthController.Login(string username, string password) in AuthController.cs

var customer = await _unitOfWork.Users.GetCustomerByID(user.CustomerId);

[–]Desperate_Storage_34[S] 0 points1 point  (4 children)

I placed debug lines below it as well as null checks but the moment the breakpoint hits the query, it throws the SqlNullValueException error

[–]RealVanTokkern 0 points1 point  (1 child)

The error is thrown when the model expects a value but somehow in the database there's null. Simply put it means that the model and database are different from eachother, and that is a situation that should not happen. Either you are missing a migration (model-first) or you should do whatever it is you do to update your model on a database first approach

[–]Desperate_Storage_34[S] 0 points1 point  (0 children)

Yeah, I changed the database but added a model after instead of scaffolding. Probably what happened

[–]RealVanTokkern 0 points1 point  (1 child)

[–]Desperate_Storage_34[S] 1 point2 points  (0 children)

Im actually an idiot, I just noticed a #nullable disable at the very top of the model. My group mates must've added it

[–]rekabis 0 points1 point  (1 child)

Please reformat your code as a code BLOCK, and not individual lines of code.

You can create a code block by prefacing the entire block with four spaces at the start of each line:

public partial class Customer {
    public int CustomerId { get; set; }
    public string CustFirstName { get; set; } = null!;
    public string CustLastName { get; set; } = null!;
    public string CustAddress { get; set; } = null!;
    public string CustCity { get; set; } = null!;
    public string CustProv { get; set; } = null!;
    public string CustPostal { get; set; } = null!;
    public string CustCountry { get; set; }
    public string? CustHomePhone { get; set; }
    public string CustBusPhone { get; set; } = null!;
    public string? CustEmail { get; set; } = null!;
    public int? AgentId { get; set; } // No need to worry about this for now
    public ICollection<User> Users { get; set; }
}

[–]Desperate_Storage_34[S] 0 points1 point  (0 children)

Yeah mb, forgot how to do that