I have 2 Tables : User and Profile.
I'm french, the database is written in french too (strange but it is like that), it is important to explain my problem.
Each user (Utilisateur in french) can reference more than one profile.
All C# classes for EF begin with Entity but the table begin with DM (Data Manager).
Code: Select all
[Table("DMUtilisateur", Schema = "GDD")]
public class EntityUtilisateur
{
public EntityUtilisateur()
{ // Create relationship many to many
ListProfiles = new HashSet<EntityProfile>();
}
[Key]
public Int64 UtilisateurID { get; set; }
[Required][MaxLength(64)]
public String Name { get; set; }
[Required][MaxLength(32)]
public String Password { get; set; }
/// <summary>
/// Make relationship many to many.
/// </summary>
public ICollection<EntityProfile> ListProfiles { get; set; }
}
And :
/// <summary>
/// Table des profiles. Contient la liste des profiles
/// </summary>
[Table("DMProfile", Schema = "GDD")]
public class EntityProfile
{
/// <summary>
/// Constructeur.
/// </summary>
public EntityProfile()
{ // Création des la relation many to many
ListUtilisateurs = new HashSet<EntityUtilisateur>();
}
/// <summary>
/// Clef primaire de la table.
/// </summary>
/// <value>Identifiant unique de la table</value>
[Key]
public Int64 ProfileID { get; set; }
/// <summary>
/// Clef primaire de la table.
/// </summary>
/// <value>Nom du profile</value>
[Required][MaxLength(128)]
public String Nom { get; set; }
/// <summary>
/// Permet de faire une relation de type many to many entre les utilisateurs et leurs profiles.
/// </summary>
/// <value>Liste des utilisateurs contenant ce profile.</value>
public ICollection<EntityUtilisateur> ListUtilisateurs { get; set; }
}
Several problems :
- My both Tables are prefix with data annotation that indicate the real name of the table : [Table("DMUtilisateur", Schema = "GDD")] and [Table("DMProfile", Schema = "GDD")] => These prefix are not taken into account when generating the new table, it generate : dbo.EntityUtilisateurEntityProfiles instead of GDD.DMUtilisateurDMProfiles
- dbo is not good, both table use GDD as schema.
- EntityUtilisateurEntityProfiles is not good because it should generated DMUtilisateurDMProfile if it correctly use the data annotations.
- EntityUtilisateurEntityProfiles is not good because it makes more than 30 char length and Oracle don't want it (OracleEntityProviderConfig.Instance.CodeFirstOptions.TruncateLongDefaultNames = true has no effect but it's work fine on simple Foreign keys.
In Configuration class, derived from DbMigrationsConfiguration<DataManager.DatabaseManagerContextApp>
I wrote :
Code: Select all
SetSqlGenerator(OracleConnectionInfo.InvariantName, new OracleEntityMigrationSqlGenerator());
AutomaticMigrationsEnabled = false;
OracleEntityProviderConfig.Instance.CodeFirstOptions.TruncateLongDefaultNames = true;
Code: Select all
[DbConfigurationType(typeof(Devart.Data.Oracle.Entity.OracleEntityProviderServicesConfiguration))]
public class DatabaseManagerContext : DbContext
...
...
...
Into the constructor :
var config = Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfig.Instance;
//config.Workarounds.IgnoreSchemaName = true; <<-- Whould I set It to true ?
config.Workarounds.ColumnTypeCasingConventionCompatibility = true;
Configuration.LazyLoadingEnabled = false;
- Rename Table 'Utilisateur' to 'User' but strange to write all in french and one in english.
- Modify the source code generated by EF by modify the name of the tables (may be some problems after ?). And I make lot of new generation from empty database (begin of developpement), I can waste a lot of time to modify the code each time I generate it.
Do you have a good workaround ? It'll be corrected in future version ?
Thanks for your reply.