Comments (15)
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.
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.
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.
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.
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.
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.
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.
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.
Currently trying to achieve this, no success so far
from sampsharp.
Hoping forward, you will solve it.
from sampsharp.
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.
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.
well, that's sad but we can't change it
thanks for your effort and i will try out NHibernate then
from sampsharp.
@Just0wned NHibernate has just as many (if not more) features as entity framework so I'm sure it will suit your purposes.
from sampsharp.
@ikkentim i just successfully implemented NHibernate in my project, thanks for the suggestion
from sampsharp.
Related Issues (20)
- player.Vehicle returns EntityID instead of Vehicle HOT 4
- "I couldn't load any gamemode scripts" What is wrong here? HOT 1
- Actor.Position should not be settable HOT 2
- VehicleModelType as command parameter HOT 4
- Runtime error on Linux HOT 2
- Bug when get Component values in GameModeExit HOT 3
- config.json support on open.mp HOT 1
- Vistual Studio won't stop on breakpoint or not debugging when error occurrs HOT 3
- Failed to initialize CoreCLR runtime. Error -1 HOT 11
- Add overload for AddComponent method that takes an instance value
- Add interfaces to SampSharp.Entities.SAMP.Components for unit-testing
- open.mp HOT 5
- Loading error
- (question): coexistence compatibility between an existing gamemode and sampsharp HOT 2
- Exception on player disconnect/crash when a Dialog window is active
- .NET dependencies resolving not working as expected HOT 3
- Game crashes after pushing game mode to Linux hosting. HOT 1
- [Question] Old SAMP plugins HOT 2
- What would it take to update to a newer .NET version? HOT 8
- Why are command names not case-insensitive?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sampsharp.