Reputation: 3469
I have tried to get EF core to scaffold a MySQL DB using DB first and Pomelo but can't run simple queries because of the tinyint(1) to bool cast failure issue. Tried using both of these connection strings for scaffolds:
Scaffold-DbContext "Server=ip.address.here;Database=DBNameUsername=UnameHere;Password=PasswordHereTreatTinyAsBoolean=false;" Pomelo.EntityFrameworkCore.MySQL -OutputDir Models -force
Scaffold-DbContext "Server=ip.address.here;Database=DBNameUsername=UnameHere;Password=PasswordHereTreatTinyAsBoolean=true;" Pomelo.EntityFrameworkCore.MySQL -OutputDir Models -force
If anyone could point out what's wrong that'd be great
public static Customer GetCustomerById(int id)
{
try
{
Customer customer = new Customer();
using (Context db = new Context())
{
customer = db.Customer.Single(c => c.CustomerId == id);
}
return customer;
}
catch (Exception err)
{
// always errors on cast conversion failure here
Console.WriteLine("error: " + err);
throw new Exception($"couldn't find the customer with CustomerId: {id}");
}
}
here is the scaffold-ed model:
using System;
using System.Collections.Generic;
namespace Scheduler.Data.Models
{
public partial class Customer
{
public Customer()
{
Appointment = new HashSet<Appointment>();
}
public int CustomerId { get; set; }
public string CustomerName { get; set; }
public int AddressId { get; set; }
public sbyte Active { get; set; }
public DateTime CreateDate { get; set; }
public string CreatedBy { get; set; }
public DateTime LastUpdate { get; set; }
public string LastUpdateBy { get; set; }
public virtual Address Address { get; set; }
public virtual ICollection<Appointment> Appointment { get; set; }
}
}
Upvotes: 0
Views: 1138
Reputation: 890
for tinyint(1) column in table we used bool property in model and managed it manually. It worked
Upvotes: 1