entity-framework-5

What is the difference between JSON.NET DataContractJsonSerializer and the Newtonsoft JSON serializer

落花浮王杯 提交于 2019-12-30 05:44:41
问题 Can someone help me. What's the difference between the built in JSON.NET DataContractJsonSerializer and the Newtonsoft JSON serializer? Is it correct that I can use one or the other with Web API and why would I choose one? 回答1: You can find the comparison of the performance here (source: newtonking.com) Here is the feature comparison, http://james.newtonking.com/projects/json/help/index.html?topic=html/JsonNetVsDotNetSerializers.htm 来源: https://stackoverflow.com/questions/17334930/what-is-the

How should I seed data to many to many relation in Entity Framework Code first 5.0

送分小仙女□ 提交于 2019-12-30 01:12:30
问题 I am having my first steps in EF 5.0 I have a many to many relationship. Movie can Have multiple Types and Type can have multiple Movies public class Movie { public int MovieId { get; set; } [Required] public string Name { get; set; } public virtual ICollection<Type> Types { get; set; } } public class Type { public int TypeId { get; set; } public string MovieType { get; set; } public virtual ICollection<Movie> Movies { get; set; } } When I generated the Database it creates many-to-many

How check by unit test that properties mark as computed in ORM model?

蹲街弑〆低调 提交于 2019-12-29 02:08:34
问题 I'm created ORM by Entity Framework 5.0 (C# 4.5) - database first. Some properties of entities i'm marked as computed (binded to columns with defaults). How check by unit test that properties mark as computed in ORM model? Note: test need for control computed properties after emergency recreate entity in ORM. Entity description in *.edmx: <EntityType Name="Users"> <Key> <PropertyRef Name="Identifier" /> </Key> <Property Name="Identifier" Type="bigint" Nullable="false" StoreGeneratedPattern=

Insertion order of multiple records in Entity Framework

狂风中的少年 提交于 2019-12-28 20:32:52
问题 I'm having trouble with EF reordering my inserts when I try and add an entity with multiple children all at once. I've got a 3 level structure with one-to-many relationships between each ( Outer 1--* Item 1--* SubItem ). If I try and insert a new Outer with Items and Subitems, the Items which contain SubItems end up being inserted first. Sample Code (.NET 4.5, EF 5.0.0-rc): public class Outer { public int OuterId { get; set; } public virtual IList<Item> Items { get; set; } } public class Item

Using MVC 4 SimpleMembership with an existing database-first EF model

这一生的挚爱 提交于 2019-12-28 10:07:25
问题 I am trying to use SimpleMembership in my MVC 4 for the first time and I already have an existing database and EF5 model created based on it! I searched a lot but I cant find how I could use it in my case and also to have everything under my own model. It would be great if somebody can give me an idea how to do this. Thanks 回答1: Purely as a point of reference, it might be a good idea to create a new Internet Application template of an ASP.NET MVC 4 Web Application project (i.e. via File > New

Windows Azure SQL Database - Identity Auto increment column skips values

安稳与你 提交于 2019-12-28 05:33:05
问题 Currently working on an ASP.Net MVC 4 application using Entity Framework 5. Used CodeFirst for initial development phase. But have now disabled the Automatic Migrations and designing new tables directly using SSMS and writing POCO. Everything is working good. Recently, identified a weird issue in Production. The records in one of the initially designed tables skipped auto-increment identity value by more than 900 numbers. This has happened 3 times within last 3 months. Debugged the

Automatic Migrations for ASP.NET SimpleMembershipProvider

我们两清 提交于 2019-12-28 03:18:10
问题 So I tried to use automatic migrations with my new MVC 4 Project but somehow it isn't working. I followed this blog post step by step. I've added the changes to the UserProfile account model (the NotaryCode field): [Table("UserProfile")] public class UserProfile { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int UserId { get; set; } public string UserName { get; set; } public int NotaryCode { get; set; } } Then I wrote on the package manager console enable

EF Lambda: The Include path expression must refer to a navigation property [duplicate]

[亡魂溺海] 提交于 2019-12-28 03:11:48
问题 This question already has answers here : EF: Include with where clause (2 answers) Closed 2 years ago . Here is my expression: Course course = db.Courses .Include( i => i.Modules.Where(m => m.IsDeleted == false) .Select(s => s.Chapters.Where(c => c.IsDeleted == false)) ).Include(i => i.Lab).Single(x => x.Id == id); I know the cause is Where(m => m.IsDeleted == false) in the Modules portion, but why does it cause the error? More importantly, how do I fix it? If I remove the where clause it

Entity Framework - attribute IN Clause usage

走远了吗. 提交于 2019-12-28 02:00:08
问题 I need to filter some Entities by various fields using "normal" WHERE and IN clauses in a query over my database, but I do not know how to do that with EF. This is the approach: Database table Licenses ------------- license INT number INT name VARCHAR ... desired SQL Query in EF SELECT * FROM Licenses WHERE license = 1 AND number IN (1,2,3,45,99) EF Code using (DatabaseEntities db = new DatabaseEntities ()) { return db.Licenses.Where( i => i.license == mylicense // another filter ).ToList();

Creating Composite Key Entity Framework

社会主义新天地 提交于 2019-12-27 12:00:27
问题 Shortly, I want to create composite keys on my table remaining with the primary key in order to improve sql server search performance. The performance issue occurs on 200k data table whenever I search an entity without primary key (i.e a string of GUID). Assume that I have 3 classes public class Device{ public int ID { get; set; } public string UDID { get; set; } public string ApplicationKey { get; set; } public string PlatformKey { get; set; } public ICollection<NotificationMessageDevice>