Giter VIP home page Giter VIP logo

Comments (15)

Strichinger avatar Strichinger commented on August 26, 2024

Her is my app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="DataContext" providerName="MySql.Data.MySqlClient" connectionString="Data Source=localhost; port=3306; Initial Catalog=SampServer; uid=*****; pwd=*****;" />
  </connectionStrings>
</configuration>

from sampsharp.

Strichinger avatar Strichinger commented on August 26, 2024

And my classes (in an dll which the gamemode references):

using MyLifeData.Source.Entities;
using MySql.Data.Entity;
using System;
using System.Data.Common;
using System.Data.Entity;
using System.IO;
using System.Linq;

namespace MyLifeData.Source
{
    [DbConfigurationType(typeof(MySqlEFConfiguration))]
    public class DataContext : DbContext
    {
        public DataContext()
            : base("DataContext")
        {
            DbConfiguration.SetConfiguration(new MySqlEFConfiguration());
            Database.SetInitializer<DataContext>(new CreateDatabaseIfNotExists<DataContext>());
        }

        public virtual DbSet<PlayerEntity> Players { get; set; }
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyLifeData.Source.Entities
{
    public abstract class EntityBase
    {
        [Column("id")]
        [Key, Required, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public long ID { get; set; }
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyLifeData.Source.Entities
{
    [Table("player")]
    public class PlayerEntity : EntityBase
    {
        [Column("name")]
        [Required(AllowEmptyStrings = true)]
        [DisplayFormat(ConvertEmptyStringToNull = false)]
        [DefaultValue("")]
        public string Name { get; set; }

        [Column("admin")]
        [Required]
        [DefaultValue(false)]
        public bool Admin { get; set; }
    }
}

from sampsharp.

Strichinger avatar Strichinger commented on August 26, 2024

I used the NuGet package "MySql.ConnectorNET.Entity" which depends on the packages "EnityFramework (>= 6.0.1)" and "MySQL.ConnectorNET.Data (>= 6.8.3)".

from sampsharp.

ikkentim avatar ikkentim commented on August 26, 2024

I've tried it a couple of weeks ago and couldn't get it to work, but i didn't spend a lot of time finding the issue. Will check this out when I get home, I know it is possible.

from sampsharp.

Strichinger avatar Strichinger commented on August 26, 2024

I tried it now using the (localdb)\v11.0 database. It works if i do it in a normal console application, but when it comes to the gamemode:

 An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.

    Inner exception:
    The provider did not return a ProviderManifestToken string.

        Inner exception:
        Could not resolve host '.'

from sampsharp.

Strichinger avatar Strichinger commented on August 26, 2024

And when setting up the connection directly in the code instead of the app.config i just get:

using connectionstring "(LocalDb)\v11.0":
Could not resolve host '(LocalDb)'

using connectionstring "(LocalDb)/v11.0":
Server does not exist or connection refused.

But also not in the test console application...

Connection string:

SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder()
{
    DataSource = "(LocalDb)/v11.0",
    InitialCatalog = "Data",
    IntegratedSecurity = true,
    ConnectTimeout = 30,
    Encrypt = false,
    TrustServerCertificate = false
};

The app.config method:

  <connectionStrings>
    <add name="DataContext" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=Data;Integrated Security=true" />
  </connectionStrings>

from sampsharp.

Strichinger avatar Strichinger commented on August 26, 2024

SampSharp is using Mono 2.0 (mono-2.0.dll ?, i'm not sure about this), right?

Maybe it's because

As of Mono 2.11.3, Microsoft's open sourced EntityFramework is part of Mono's distribution. 

http://www.mono-project.com/EntityFramework

from sampsharp.

ikkentim avatar ikkentim commented on August 26, 2024

Afaik Sampsharp is using the latest mono version. For reasons unknown
the main mono library is called mono2.0. You will be able to find
entity framework libraries in /environment/mono

from sampsharp.

ikkentim avatar ikkentim commented on August 26, 2024

Currently trying to achieve this, no success so far

from sampsharp.

Strichinger avatar Strichinger commented on August 26, 2024

Hoping forward, you will solve it.

from sampsharp.

ikkentim avatar ikkentim commented on August 26, 2024

I've been debugging this problem, and it seems there are tiny differences between MS' EF and mono's EF. I were unable to get the MySQL library to work with mono's EF. I've also tried dotconnect. Apart from being a payed library I din't get it to cooperate either. I'll keep trying, but if I don't get it to work I'll need to build my own ORM library. Also, see #12.

from sampsharp.

ikkentim avatar ikkentim commented on August 26, 2024

It's been a struggle. But my final conclusion is that I can't get EF to work with SampSharp. Sort of a bummer, BUT there is a different awesome library called NHibernate. I've tested it out and created an example here: https://github.com/ikkentim/SampSharp/tree/master/src/NHibernateTest . It's been way less struggle to set this project op then to setup a EF+mysql project. NHibernate is said to have good support for mono/linux. In my example NHibernate with FluentHibernate, to avoid issues like #12 and also for it's awesomeness.

from sampsharp.

Strichinger avatar Strichinger commented on August 26, 2024

well, that's sad but we can't change it
thanks for your effort and i will try out NHibernate then

from sampsharp.

ikkentim avatar ikkentim commented on August 26, 2024

@Just0wned NHibernate has just as many (if not more) features as entity framework so I'm sure it will suit your purposes.

from sampsharp.

Strichinger avatar Strichinger commented on August 26, 2024

@ikkentim i just successfully implemented NHibernate in my project, thanks for the suggestion

from sampsharp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.