entity-framework-6

Why this app is trying to connect to SQL Server instead of SQLite?

泄露秘密 提交于 2020-06-01 05:06:25
问题 Environment : VS2019 , .NET 4.8 , EF 6 , SQLite , WPF App (.NET Framework) I am following this Microsoft official tutorial to create a code-first app, called WPF_EF6 using SQLite. With the configuration shown below, I am getting an error about failing to connect to SQL Server. But as you can see in the App.config file below, there is no SQL Server is involved here? Question : what may I be missing here? And how can we resolve the issue? App compiles fine but throws this runtime error. I

Entity Framework Code First Seed database

前提是你 提交于 2020-05-28 03:15:46
问题 I am using E.F. with Code First approach... Now I have to fill the database with some data... but I cannot do it easily... Simething is not clear... I have googled but every solution I have found suppose I must create a custom Initilization... but I do not want to create a custom Initialization.. What I need is a method the everytime I launch some tests DROP the database, RE-CREATE it and fill it with some data. What I have tried to do is: public PublicAreaContext() : base("PublicAreaContext"

EntityFramework : Invalid column name *_ID1

折月煮酒 提交于 2020-05-24 22:33:51
问题 I am trying to implement DbContext for couple of tables called ' Employee ' and ' Department ' Relationship between Employee and Department is many to one. i.e. department can have many employees. Below are the EntityFramework classes I designed ( CodeFirst approach ) [Table("Employee")] public class Employee { [DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)] public int Id { get; set; } [Column("Name")] public string Name { get; set; } [Column

Create table and insert data into it during EF code first migration

倖福魔咒の 提交于 2020-04-08 02:44:12
问题 I'm using Entity Framework Code First with Code First migrations. During a migration, I need to create a new table, and then insert some data into it. So I create the table with : CreateTable("MySchema.MyNewTable", c => new { MYCOLUMNID = c.Int(nullable: false, identity: true), MYCOLUMNNAME = c.String(), }) .PrimaryKey(t => t.MYCOLUMNID); Then I try to insert data with : using (var context = new MyContext()) { context.MyNewTableDbSet.AddOrUpdate(new[] { new MyNewTable { MYCOLUMNNAME = "Test"

Entity Framework 6 DbSet AddRange vs IDbSet Add - How Can AddRange be so much faster?

ⅰ亾dé卋堺 提交于 2020-03-18 11:27:33
问题 I was playing around with Entity Framework 6 on my home computer and decided to try out inserting a fairly large amount of rows, around 430k. My first try looked like this, yes I know it can be better but it was for research anyway: var watch = System.Diagnostics.Stopwatch.StartNew(); foreach (var event in group) { db.Events.Add(event); db.SaveChanges(); } var dbCount = db.Events.Count(x => x.ImportInformation.FileName == group.Key); if (dbCount != group.Count()) { throw new Exception(

Entity Framework 6 DbSet AddRange vs IDbSet Add - How Can AddRange be so much faster?

一曲冷凌霜 提交于 2020-03-18 11:27:10
问题 I was playing around with Entity Framework 6 on my home computer and decided to try out inserting a fairly large amount of rows, around 430k. My first try looked like this, yes I know it can be better but it was for research anyway: var watch = System.Diagnostics.Stopwatch.StartNew(); foreach (var event in group) { db.Events.Add(event); db.SaveChanges(); } var dbCount = db.Events.Count(x => x.ImportInformation.FileName == group.Key); if (dbCount != group.Count()) { throw new Exception(

Why does this EF insert with IDENTITY_INSERT not work?

ぃ、小莉子 提交于 2020-03-18 03:57:48
问题 This is the query: using (var db = new AppDbContext()) { var item = new IdentityItem {Id = 418, Name = "Abrahadabra" }; db.IdentityItems.Add(item); db.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Test.Items ON;"); db.SaveChanges(); } When executed, the Id of the inserted record, on a new table, is still 1. NEW: When I use either the transaction, or TGlatzer's answer, I get the exception: Explicit value must be specified for identity column in table 'Items' either when IDENTITY_INSERT is

EF code first, Entities with multiple relations

蹲街弑〆低调 提交于 2020-03-06 04:16:34
问题 Here you can see my reduced entity structure which I would like to store in my Sqlite database. I've a Graph which holds a Set of GraphElements . My Graph consists of Edges , Nodes and Loads which are all different Elements. For a deep-first-search for example each node needs to know its neighbor nodes. Therefore I need the NeigborNodes -List. For other functionalities I need also to know the ConnectedElements -List. class Graph { public int Id { get; set; } public string Name { get; set; }

EF code first, Entities with multiple relations

守給你的承諾、 提交于 2020-03-06 04:14:16
问题 Here you can see my reduced entity structure which I would like to store in my Sqlite database. I've a Graph which holds a Set of GraphElements . My Graph consists of Edges , Nodes and Loads which are all different Elements. For a deep-first-search for example each node needs to know its neighbor nodes. Therefore I need the NeigborNodes -List. For other functionalities I need also to know the ConnectedElements -List. class Graph { public int Id { get; set; } public string Name { get; set; }

Entity Framework 6 - inheritance and navigation properties on base class

喜欢而已 提交于 2020-02-21 06:30:13
问题 I have a problem with navigation properties and inheritance. This is my problem: I have a base Person class and classes User and Worker which inherit from Person . On the DB level I'm using single table inheritance or table per hierarchy (TPH) inheritance. So there a single table with a discriminator column. Both User and Worker need to have a Company relation, so I would like to define it on the Person class. I define my model like this: [Table("mydb.person")] public abstract partial class