I try to make a library for access to an Interbase database on a server. Following the samples provided by embarcadero here I end up with a scaffolded database context without any error.
public partial class CZehetnerDBWPSTEYRXEIBContext : DbContext
{
public CZehetnerDBWPSTEYRXEIBContext()
{
}
public CZehetnerDBWPSTEYRXEIBContext(DbContextOptions<CZehetnerDBWPSTEYRXEIBContext> options)
: base(options)
{
}
public virtual DbSet<Aktion> Aktions { get; set; } = null!;
...
// this is the table I want to query
public virtual DbSet<Executedalarm> Executedalarms { get; set; } = null!;
......
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseInterBase("Same as used for scaffolding, onnection is OK");
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
....
modelBuilder.Entity<Executedalarm>(entity =>
{
entity.HasKey(e => e.LfdNr)
.HasName("RDB$PRIMARY9");
entity.ToTable("EXECUTEDALARMS");
entity.HasIndex(e => e.Executed, "EXECUTEDALARMS_IDXDT");
entity.Property(e => e.LfdNr).HasColumnName("LFD_NR");
entity.Property(e => e.AaId).HasColumnName("AA_ID");
entity.Property(e => e.Alarmsource)
.HasMaxLength(50)
.HasColumnName("ALARMSOURCE");
entity.Property(e => e.Alarmtext)
.HasMaxLength(120)
.HasColumnName("ALARMTEXT");
entity.Property(e => e.Annahme).HasColumnName("ANNAHME");
entity.Property(e => e.Computer)
.HasMaxLength(50)
.HasColumnName("COMPUTER");
entity.Property(e => e.Ersrte)
.HasColumnType("CHAR(1)")
.HasColumnName("ERSRTE")
.HasDefaultValueSql("'N'");
entity.Property(e => e.Executed).HasColumnName("EXECUTED");
entity.Property(e => e.Hdld)
.HasColumnType("CHAR(1)")
.HasColumnName("HDLD");
entity.Property(e => e.IdAr).HasColumnName("ID_AR");
entity.Property(e => e.IdIt).HasColumnName("ID_IT");
entity.Property(e => e.IdPrio).HasColumnName("ID_PRIO");
entity.Property(e => e.IdRcv).HasColumnName("ID_RCV");
entity.Property(e => e.IdStation).HasColumnName("ID_STATION");
entity.Property(e => e.Itimestamp).HasColumnName("ITIMESTAMP");
entity.Property(e => e.Name)
.HasMaxLength(50)
.HasColumnName("NAME");
entity.Property(e => e.Number)
.HasMaxLength(20)
.HasColumnName("NUMBER");
entity.Property(e => e.Sds)
.HasMaxLength(5)
.HasColumnName("SDS");
entity.Property(e => e.Sms)
.HasMaxLength(20)
.HasColumnName("SMS");
entity.Property(e => e.Success).HasColumnName("SUCCESS");
entity.Property(e => e.UrId).HasColumnName("UR_ID");
entity.Property(e => e.Username)
.HasMaxLength(30)
.HasColumnName("USERNAME");
entity.HasOne(d => d.Ur)
.WithMany(p => p.Executedalarms)
.HasForeignKey(d => d.UrId)
.OnDelete(DeleteBehavior.Restrict)
.HasConstraintName("FK_EXECUTED_REF_580_USERREGI");
});
....
This is all generated code from the Scaffold-DbContext command, I have not changed anything.
Now when I try to use this scaffolded model, I ran into an exception:
using (CZehetnerDBWPSTEYRXEIBContext db = new CZehetnerDBWPSTEYRXEIBContext())
{
// throws exception
var alarms = db.Executedalarms.Where(p => p.LfdNr == 1000).ToList();
}
InterBaseSql.Data.InterBaseClient.IBException:
'Dynamic SQL Error SQL error code = -104 Token unknown - line 1, column 11.'
Does anyone know what this means? What is SQL error code -104? Which "Token" may be wrong here?
Here is the generated code for the class of the record:
public partial class Executedalarm
{
public int LfdNr { get; set; }
public int? UrId { get; set; }
public DateTime? Annahme { get; set; }
public DateTime? Executed { get; set; }
public int? IdStation { get; set; }
public int? IdRcv { get; set; }
public int? IdIt { get; set; }
public string? Number { get; set; }
public string? Sms { get; set; }
public string? Name { get; set; }
public string? Alarmtext { get; set; }
public string? Alarmsource { get; set; }
public string? Computer { get; set; }
public string? Username { get; set; }
public int? AaId { get; set; }
public int? Success { get; set; }
public int? Itimestamp { get; set; }
public string? Hdld { get; set; }
public int? IdAr { get; set; }
public int? IdPrio { get; set; }
public string? Ersrte { get; set; }
public string? Sds { get; set; }
public virtual Userregist? Ur { get; set; }
}
Interesting, this works ...
var alarms = db.Executedalarms.FromSqlRaw($"SELECT * FROM EXECUTEDALARMS WHERE Lfd_Nr = 1000").ToList();