I get this error:
An exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.dll but was not handled in user code
Additional information: Directory lookup for the file "C:\pub\LSK\Dev\src\LSK.Services\LSK.Services\App_Data\LSK.Packets.mdf" failed with the operating system error 2(The system can not find the specified file).
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
using (var context = new LDTContext())
{
context.Packets.AddRange(packets); // Here occurs the exception
context.SaveChanges();
}
public class LDTContext : DbContext
{
public LDTContext()
: base("name=LDTContext")
{
Configuration.LazyLoadingEnabled = true;
Configuration.ProxyCreationEnabled = true;
Configuration.ValidateOnSaveEnabled = true;
Configuration.AutoDetectChangesEnabled = true;
Configuration.UseDatabaseNullSemantics = false;
}
public DbSet<Packets> Packets{ get; set; }
}
In my app.config:
<add name="LDTContext" connectionString="Server=(LocalDb)\LSK;Initial Catalog=LSK.Packets;Integrated Security=true;AttachDBFilename=|DataDirectory|\LSK.Packets.mdf" providerName="System.Data.SqlClient" />
Why is the database not created on the first AddRange() when data is pushed into the tables?