I am currently developing an ASP.NET MVC / WebApi project with Entity Framework 6, which requires exchange databases (MSSQL, MySQL / MariaDB, Postgresql).
We use a code-based approach in our project, so I followed this multi-page guide of several vendors to be able to use several databases in one project at the same time.
To achieve the same db structure everywhere, I made one abstract context with all my tables, etc., from which my "real" contexts inherit the structure. Then, at run time, the ContextFactory decides which context should be created.
using (AbstractContext ctxt = ContextFactory.GetContext())
{
(...)
}
Everything is still working as intended. MSSQL obviously works, and also Postgres works like a charm, not a SQL generation error / problem that it ever has.
Then I tried to add support for MySql / MariaDB. The first issue was the MySql.Data.Entity inheritance security bug in the latest version, which made me downgrade to 6.9.10.
The next thing to do is manually configure MigrationSqlgenerator by adding:
public Configuration()
{
SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
}
To my reconfiguration configuration, Configuration_MySQL.cs, which matches the Context used for my MySql database.
After that, at least I was able to add-reconfigure and update the database on my MySql server. But after trying to launch the site, it crashed all the time with this exception:
System.Data.Entity.Core.EntityCommandExecutionException
HResult = 0x8013193C 1: MySqlException: 'Extent1.PlantSectionId' 'where where'
Linq-Query:
List<StatusCard> PlantSectionCards = (
from ps in ctxt.PlantSections
select new StatusCard()
{
LatestAlertMessage = (from al in ctxt.AlertLogs
where al.Alert.PlantSectionId == ps.PlantSectionId
where al.TimestampEnd == null
orderby al.TimestampBegin descending
select al.Alert.AlarmText
).FirstOrDefault(),
}).ToList();
:
SELECT
`Apply1`.`PlantSectionId`, `Apply1`.`AlarmText`
FROM
(SELECT
`Extent1`.`PlantSectionId`,
(SELECT
`Project1`.`TimestampBegin`
FROM
(SELECT
`Extent2`.`TimestampBegin`, `Extent3`.`AlarmText`
FROM
`AlertLog` AS `Extent2`
INNER JOIN `Alert` AS `Extent3` ON `Extent2`.`AlarmId` = `Extent3`.`AlarmId`
WHERE
(`Extent3`.`PlantSectionId` = `Extent1`.`PlantSectionId`)
AND (`Extent2`.`TimestampEnd` IS NULL)) AS `Project1`
ORDER BY `Project1`.`TimestampBegin` DESC
LIMIT 1) AS `TimestampBegin`,
(SELECT
`Project1`.`AlarmText`
FROM
(SELECT
`Extent2`.`TimestampBegin`, `Extent3`.`AlarmText`
FROM
`AlertLog` AS `Extent2`
INNER JOIN `Alert` AS `Extent3` ON `Extent2`.`AlarmId` = `Extent3`.`AlarmId`
WHERE
(`Extent3`.`PlantSectionId` = `Extent1`.`PlantSectionId`)
AND (`Extent2`.`TimestampEnd` IS NULL)) AS `Project1`
ORDER BY `Project1`.`TimestampBegin` DESC
LIMIT 1) AS `AlarmText`
FROM
`PlantSection` AS `Extent1`) AS `Apply1`;
Workbench Error 1054 Unknown column.
, , SQL.
SELECT
`Extent1`.`PlantSectionId`,
(SELECT
`Extent3`.`AlarmText`
FROM
`AlertLog` AS `Extent2`
INNER JOIN
`Alert` AS `Extent3` ON `Extent2`.`AlarmId` = `Extent3`.`AlarmId`
WHERE
(`Extent3`.`PlantSectionId` = `Extent1`.`PlantSectionId`)
AND (`Extent2`.`TimestampEnd` IS NULL)
LIMIT 1) AS `C1`
FROM
`PlantSection` AS `Extent1`
.
, : - - , , ?