Как разыграть Tinyint (1) MySQL EF Core - PullRequest
0 голосов
/ 19 июня 2019

Я пытался заставить ядро ​​EF компилировать базу данных MySQL с использованием сначала БД и Pomelo, но не могу выполнить простые запросы из-за проблемы tinyint (1) bool cast.Попробовал использовать обе эти строки подключения для строительных лесов:

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

Если кто-нибудь может указать, что не так, было бы здорово

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}");
        }
    }

вот модель подмостей:

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; }
    }
}

1 Ответ

0 голосов
/ 19 июня 2019

для столбца tinyint (1) в таблице мы использовали свойство bool в модели и управляли им вручную. Сработало

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...