0

i was wondering if it is possible to seperate the database and entity framework to a new .net-core project?

i have a simple Solution like this

Project database.core (.net standard 2.0)

Project database.tester.net461 (.net Framework 4.6.1)

The main Program.cs of project database.tester.net461

using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using database.core;

namespace database.tester.net461
{
class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello World!");
        ListUsers("SomeCoolUser");
    }

    static void ListUsers(string username)
    {
        using (var db = new C2Crayfire())
        {
            WriteLine("--------------------------------------------");
            WriteLine("| UserID | UserGUID | Username | RecoveryMail");
            WriteLine("---------------------------------------------------");

            crayfire_User singleuser = db.crayfire_user.Where(u => u.Username.Equals(username)).First();
            WriteLine($"| { singleuser.ToString()} | { singleuser.UserGUID} | { singleuser.Username} | { singleuser.RecoveryMail}  | ");

            WriteLine("---------------------------------------------------");
            Console.ReadLine();
        }

    }
}
}

No im struggeling using the database.core in the console project. When i start the programm hey says the following error

System.TypeLoadException: "The method "ApplyServices" in type "MySql.Data.EntityFrameworkCore.Infraestructure.MySQLOptionsExtension" of Assembly "MySql.Data.EntityFrameworkCore, Version=6.10.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" has no implementation."

If you need any further informations just ask.

Greetings XRJPK

For information the code of the database.core project

using System.ComponentModel.DataAnnotations;

namespace database.core
{
public class crayfire_User
{
    // these properties map to columns in the database
    [Required]   
    [Key]
    public int UserID { get; set; }

    public string UserGUID { get; set; }

    public string Username { get; set; }

    public string RecoveryMail { get; set; }

    public string Password { get; set; }

    public string Salt { get; set; }

    public crayfire_User()
    {

    }
}
}

The C2Crayfire Class

using System;
using Microsoft.EntityFrameworkCore;
using MySql.Data.EntityFrameworkCore;

namespace database.core
{
// this manages the connection to the database
public class C2Crayfire : DbContext
{
    public DbSet<crayfire_User> crayfire_user { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseMySQL("server = <servername>; user id = <userid>; password = <password>; database = <database>");
    }
}
}
XRJPK
  • 63
  • 1
  • 8

0 Answers0