I am using Entity Framework 6 with MySql Db. I have downloaded and install the trial version of dotconnect for mysql. Now i am trying to implement dotconnect to my project. I am using .net core cli to add migrations. I have referenced the Devart.Data.dll, Devart.Data.MySql.dll and Devart.Data.MySql.Entity.EF6.dll to my entityframework project. I have created custom dbconfiguration class which you can see below.
Code: Select all
[DbConfigurationType(typeof(BookAndAdDbConfiguration))]
public class BookAndAdDbContext : AbpZeroDbContext<Tenant, Role, User>
{
/* Define an IDbSet for each entity of the application */
public virtual IDbSet<BinaryObject> BinaryObjects { get; set; }
public virtual IDbSet<Friendship> Friendships { get; set; }
public virtual IDbSet<ChatMessage> ChatMessages { get; set; }
public virtual IDbSet<Advertiser> Advertisers { get; set; }
public virtual IDbSet<Agreement> Agreements { get; set; }
public virtual IDbSet<ShareHolder> ShareHolders { get; set; }
public virtual IDbSet<Offer> Offers { get; set; }
public virtual IDbSet<OfferPdfFile> OfferPdfFiles { get; set; }
public virtual IDbSet<Group> Groups { get; set; }
public virtual IDbSet<MediaLength> MediaLengths { get; set; }
public virtual IDbSet<RuleSet> RuleSets { get; set; }
public virtual IDbSet<Screen> Screens { get; set; }
public virtual IDbSet<Tag> Tags { get; set; }
public virtual IDbSet<Seller> Sellers { get; set; }
public virtual IDbSet<Availability> Availabilities { get; set; }
public virtual IDbSet<Associate> Associates { get; set; }
public virtual IDbSet<Address> Addresses { get; set; }
public virtual IDbSet<Phone> Phones { get; set; }
public virtual IDbSet<City> Cities { get; set; }
public virtual IDbSet<Country> Countries { get; set; }
public virtual IDbSet<BookedOffer> BookedOffers { get; set; }
public virtual IDbSet<Playlist> Playlists { get; set; }
public virtual IDbSet<Content> Contents { get; set; }
public BookAndAdDbContext()
: base(GetConnectionString())
{
}
private static string GetConnectionString()
{
//Notice that; this logic only works on development time.
//It is used to get connection string from appsettings.json in the Web project.
var configuration = AppConfigurations.Get(
WebContentDirectoryFinder.CalculateContentRootFolder()
);
return configuration.GetConnectionString(
BookAndAdConsts.ConnectionStringName
);
}
public BookAndAdDbContext(string nameOrConnectionString)
: base(nameOrConnectionString)
{
}
public BookAndAdDbContext(DbConnection existingConnection)
: base(existingConnection, false)
{
}
public BookAndAdDbContext(DbConnection existingConnection, bool contextOwnsConnection)
: base(existingConnection, contextOwnsConnection)
{
}
}
public class BookAndAdDbConfiguration : DbConfiguration
{
public BookAndAdDbConfiguration()
{
//Mysql Implementation
//SetProviderServices("MySql.Data.MySqlClient", new MySqlProviderServices());
//SetDefaultConnectionFactory(new MySqlConnectionFactory());
SetProviderServices("Devart.Data.MySql", Devart.Data.MySql.Entity.MySqlEntityProviderServices.Instance);
SetProviderFactory("Devart.Data.MySql", Devart.Data.MySql.MySqlProviderFactory.Instance);
//SetProviderServices(
// "System.Data.SqlClient",
// System.Data.Entity.SqlServer.SqlProviderServices.Instance
//);
}
}
and add the sqlgenerator code to the configuration constructor.
Code: Select all
public Configuration()
{
//SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
SetSqlGenerator(MySqlConnectionInfo.InvariantName, new MySqlEntityMigrationSqlGenerator());
AutomaticMigrationsEnabled = false;
ContextKey = "BookAndAd";
}
When i try to add migration from command prompt with the command dotnet ef migrations add "initialize", it is saying "Keyword not supported: 'port'." It feels like it is still trying to use ms sql connector. What am i doing wrong? And if you have a sample about custom dbconfiguration it will be so helpful. Thank you for the assistance.