I am trying to make a .NET Core Web API but I couldn't find out a solution for my problem.
Full error is
[ERR] An exception occurred in the database while iterating the results of a query for context type '"MailAlertWebApiWithEF.Data.AlertContext"'." ""System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
I get that configuration codes from an existing database with
Scaffold-DbContext "server=.;ConnectionString" Microsoft.EntityFrameworkCore.SqlServer -OutputDir DBModels -force -v
My configuration is:
public class AlertModelConfiguration<T>:BaseEntityModelConfiguration<T,int> where T:Alert
{
public AlertModelConfiguration(ref ModelBuilder modelBuilder):base(ref modelBuilder)
{
modelBuilder.Entity<Alert>(entity =>
{
//entity.HasKey(e => e.AlertId);
entity.Property(e => e.CreateDate).HasColumnType("datetime");
entity.Property(e => e.DeleteDate).HasColumnType("datetime");
entity.Property(e => e.Detail)
.IsRequired()
.HasMaxLength(2046)
.IsUnicode(false);
entity.Property(e => e.ErrorDetail)
.IsRequired()
.HasMaxLength(255)
.IsUnicode(false);
entity.Property(e => e.Title)
.HasMaxLength(50)
.IsUnicode(false);
entity.Property(e => e.UpdateDate).HasColumnType("datetime");
});
}
}
My context is:
public class AlertContext:DbContext
{
public AlertContext(DbContextOptions<AlertContext> options)
: base(options)
{
}
public virtual DbSet<Alert> Users { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
new AlertModelConfiguration<Alert>(ref modelBuilder);
base.OnModelCreating(modelBuilder);
}
}
My ConnectionStrings inside at appsettings.json:
ConnectionStrings": {
"AlertContext": "server=.;database=*****;poling=false;Connect
Timeout=60;Integrated Security=SSPI"
When I start at debug mode the API gets stuck inside the engine layer.
My Engine and IEngine:
Task<CustomListEntity<Alert>> GetByIdAsync(int id);
public Task<CustomListEntity<Alert>> GetByIdAsync(int id)
{
return CommonOperationAsync(async () =>
{
var predicate = PredicateBuilder.True<Alert>();
predicate = predicate.And(p => p.Id == id);
return new CustomListEntity<Alert>()
{
EntityList = await _alertReqository.GetAll(skip: 0, take: 10, predicate: predicate,
orderExpression: null, rowCount: out var count, ascending: false).ToListAsync(),
Count = count,
};
}, new BusinessBaseRequest()
{
MethodBase = MethodBase.GetCurrentMethod()
}, BusinessUtilMethod.CheckRecordIsExist, GetType().Name);
}
I tried my own configuration file but the result is the same. What is wrong?