entity-framework-6

Duplicate ForeignKey when using inheritance

痴心易碎 提交于 2019-12-11 01:18:18
问题 I have created these classes in order to generate the database model via EntityFramework 6 code-first approach: public class Vehicle { public long Id { get; set; } public long ResponsiblePersonId { get; set; } } public class Car: Vehicle { public int HorsePower { get; set; } } public class Bike: Vehicle { public int FrameSize { get; set; } } public class Organisation { public Organisation() { Cars = new List<Car>(); Bikes = new List<Bikes>(); } public long Id { get; set; } public List<Car>

Can you remove Identity from a primary key with Entity Framework 6?

旧巷老猫 提交于 2019-12-11 00:40:56
问题 I created a table via entity framework code-first with a primary key set to auto increment, but now I want to remove that auto-incrementing from the column. I've tried doing that with both fluent API: public class ProductTypeMap: EntityTypeConfiguration<ProductType> { public ProductTypeMap() { // This is an enum effectively, so we need fixed IDs Property(x => x.ProductTypeId) .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); } } And an annotation: public class ProductType { [Required

Entity Framework 6 - Handling loading of nested objects

荒凉一梦 提交于 2019-12-10 23:44:43
问题 Here is a simplified version of a class hierarchy I am using with entity framework. public class Questionnaire { public int Id { get; set; } public ICollection<Question> Questions { get; set; } } public class Question { public int Id { get; set; } public ICollection<Question> ChildQuestions { get; set; } // Navigation properties public int QuestionnaireId { get; set; } public virtual Questionnaire Questionnaire { get; set; } public int? ParentQuestionId { get; set; } public virtual Question

Log when entity framework 6 SqlAzureExecutionStrategy retries

不羁的心 提交于 2019-12-10 22:17:57
问题 How can I log when the SqlAzureExecutionStrategy retries an Entity Framework operation? When using the transient fault handling logic with regular SqlConnection calls, a Retrying event is exposed. Is there something similar when using the SqlAzureExecutionStrategy with Entity Framework 6? If not, what are some other options? 回答1: There is a very good article on this topic explaining all the steps for logging Azure SQL database with ASP.NET MVC and EntityFramework:. Hope this helps. Here is

SQLite connection not appearing in Entity Data Model Wizard (vs2015)

喜欢而已 提交于 2019-12-10 21:43:39
问题 What I did is, 1) Created a project in vs2015 (.Net Framework 4.6) 2) Installed System.Data.SQLite from Nuget. Actually System.Data.SQLite(1.0.105.1),System.Data.SQLite.Core(1.0.105.1),System.Data.SQLite.EF6(1.0.105.1),System.Data.SQLite.Linq(1.0.105.1),EntityFramework(6.0.0) were installed 3) Updated EntityFramework to 6.1.3 in Nuget 4) Tried to create Entity Data Model from a local Sqlite database 5) Rebuilded the whole solution But when I tried to create a new database connection, SQLite

How to use Bulk Insert in Entity Framework using Object Context?

旧城冷巷雨未停 提交于 2019-12-10 21:26:05
问题 I would like to use Object Context instead of DbContext to call Bulk Insert in Entity Framework 6. How can I do that? I would like to do something like readonly ObjectContext obContext : public void BulkInsert<T>(IEnumerable<T> items) where T : class, new() { obContext.BulkInsert(items); } But I am not able to do this. 回答1: With entity framework 6, you can use this nice nuget package to bulk insert, and you can use it with the DbContext object. so something like this: using (var db = new

How to get some columns of entity in entity-framework?

亡梦爱人 提交于 2019-12-10 21:24:17
问题 Assume I have a table with more than 1000000 columns. When I use LINQ To SQL and Entity-Framework all queries will write in c# like below: EFContext.MyTableName.Where(row=>row.column1==someValue) .Select(...) .FirstOrDefault(...) .Any(...) ... How to get only and only some columns of entity? Are there any way to get only columns 1 & 2 & 3 among 1000000 columns for example? Attention: Type of resulted data should keep after selection, for example if without filtering some columns type of

Is IDbCommandInterceptor in EntityFramework 6 thread safe

為{幸葍}努か 提交于 2019-12-10 21:22:58
问题 Is a IDbCommandInterceptor instance considered thread-safe when registered with the DbInterception add method? I have implemented a class that conforms to the IDbCommandInterceptor interface and am tracking the start time of a command when one of the executing methods are invoked compared to the stop time when the corresponding executed method is called. I'm storing this information in a private ivar list and need to know if what I'm doing is safe. 回答1: As it turns out the

EntityFramework 6.0.0.0 reads data, but it is not inserting

删除回忆录丶 提交于 2019-12-10 19:47:50
问题 I've created a Service-based Database folderName->Add New Item->Data->Service-based Database file into WPF application. Then I've used Database First approach and have created the PersonsModel.edmx file. These operations are executed perfectly. The reading of data works okay : using (PersonDBEntities db = new PersonDBEntities()) { string dep = (db.Departament.FirstOrDefault()).DepName;//data can be read perfectly string bureau = (db.Bureau.FirstOrDefault()).BureauName;//data can be read

Should I map both sides of bidirectional relations in EF code first?

若如初见. 提交于 2019-12-10 19:03:20
问题 Assume I have the following entity classes: public class Customer { public int Id { get; set; } public virtual ICollection<Order> Orders { get; set; } } public class Order { public int Id { get; set; } public virtual Customer Customer { get; set; } } How should those be mapped in Entity Framework 6 fluent code-first mapping? I want to be explicit about the mapping and not rely on automatic mapping conventions. Option 1 Just map the local properties of both classes. That's how I would do it in