Hello,
I'm trying to create a Firebird database in a small test application using Entity Framework 5 with Code First, but it doesn't work.
Versions of everything:
Windows 7 Home Premium, 64 bit
Firebird 2.5.1
Firebird net provider 2.7.7 (installed in the GAC, correct entries in machine.config)
Visual Studio 2012 Express for Desktop
The exception I get (line is shown in the code):
- InnerException {"Fehler beim Aktualisieren der Einträge. Weitere Informationen finden Sie in der internen Ausnahme."} System.Exception {System.Data.UpdateException}
[Failed to update the entries. More information, see the inner exception]
+ InnerException {"Dynamic SQL Error\r\nSQL error code = -204\r\nTable unknown\r\n__MigrationHistory\r\nAt line 1, column 8"} System.Exception {FirebirdSql.Data.FirebirdClient.FbException}
[Failed to update the entries. More information, see the inner exception]
+ InnerException {"Dynamic SQL Error\r\nSQL error code = -204\r\nTable unknown\r\n__MigrationHistory\r\nAt line 1, column 8"} System.Exception {FirebirdSql.Data.FirebirdClient.FbException}
The database is created, it has two tables: the table described in the model and a second table HistoryRow with the columns
MigrationId Varchar(255) not null, primary key
Model Blob sub_type 0 not null
ProductVersion Varchar(32) not null
Model Blob sub_type 0 not null
ProductVersion Varchar(32) not null
Both tables are empty. What is wrong?
The 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=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
<connectionStrings>
<add name="EinkaufContext"
connectionString="Database=localhost:einkauf;User=sib;Password=immergut;Charset=ISO8859_1"
providerName="FirebirdSql.Data.FirebirdClient" />
</connectionStrings>
</configuration>
<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=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
<connectionStrings>
<add name="EinkaufContext"
connectionString="Database=localhost:einkauf;User=sib;Password=immergut;Charset=ISO8859_1"
providerName="FirebirdSql.Data.FirebirdClient" />
</connectionStrings>
</configuration>
The code:
namespace CodeFirst_Konsole_1
{
class Rubrik
{
public string RUBID { get; set; }
public string RUBNAME { get; set; }
}
class EinkaufContext : DbContext
{
public EinkaufContext() : base("name=EinkaufContext")
{ }
public DbSet<Rubrik> Rubriken { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Rubrik>().ToTable("RUBRIK");
modelBuilder.Entity<Rubrik>().HasKey(t => t.RUBID);
modelBuilder.Entity<Rubrik>().Property(p => p.RUBID)
.HasMaxLength(3)
.IsFixedLength()
.IsUnicode(false);
modelBuilder.Entity<Rubrik>().Property(p => p.RUBNAME)
.IsRequired()
.HasMaxLength(50);
}
}
class EinkaufContextInitializer : DropCreateDatabaseIfModelChanges<EinkaufContext>
{
protected override void Seed(EinkaufContext context)
{
// base.Seed(context);
}
}
class Program
{
static void Main(string[] args)
{
Database.SetInitializer<EinkaufContext>(new EinkaufContextInitializer());
using (var db = new EinkaufContext())
{
var newrub = new Rubrik { RUBID = "AAC", RUBNAME = "-" };
{
class Rubrik
{
public string RUBID { get; set; }
public string RUBNAME { get; set; }
}
class EinkaufContext : DbContext
{
public EinkaufContext() : base("name=EinkaufContext")
{ }
public DbSet<Rubrik> Rubriken { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Rubrik>().ToTable("RUBRIK");
modelBuilder.Entity<Rubrik>().HasKey(t => t.RUBID);
modelBuilder.Entity<Rubrik>().Property(p => p.RUBID)
.HasMaxLength(3)
.IsFixedLength()
.IsUnicode(false);
modelBuilder.Entity<Rubrik>().Property(p => p.RUBNAME)
.IsRequired()
.HasMaxLength(50);
}
}
class EinkaufContextInitializer : DropCreateDatabaseIfModelChanges<EinkaufContext>
{
protected override void Seed(EinkaufContext context)
{
// base.Seed(context);
}
}
class Program
{
static void Main(string[] args)
{
Database.SetInitializer<EinkaufContext>(new EinkaufContextInitializer());
using (var db = new EinkaufContext())
{
var newrub = new Rubrik { RUBID = "AAC", RUBNAME = "-" };
db.Rubriken.Add(newrub); // <--- Exception here
int recordsAffected = db.SaveChanges();
Console.WriteLine("{0} Sätze in die Datenbank geschrieben.", recordsAffected);
// Abfragen
var allrubs = from p in db.Rubriken
select p;
foreach (var item in allrubs)
{
Console.WriteLine("Kennung {0}, Name {1}", item.RUBID, item.RUBNAME);
}
}
Console.WriteLine("Weiter mit jeder Taste ...");
Console.ReadKey();
}
}
}
int recordsAffected = db.SaveChanges();
Console.WriteLine("{0} Sätze in die Datenbank geschrieben.", recordsAffected);
// Abfragen
var allrubs = from p in db.Rubriken
select p;
foreach (var item in allrubs)
{
Console.WriteLine("Kennung {0}, Name {1}", item.RUBID, item.RUBNAME);
}
}
Console.WriteLine("Weiter mit jeder Taste ...");
Console.ReadKey();
}
}
}
Thank you for help,
Sibylle
------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://ad.doubleclick.net/clk;258768047;13503038;j? http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________ Firebird-net-provider mailing list Firebird-net-provider@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/firebird-net-provider