entity-framework-6

Can we use enums as typesafe entity ids?

六眼飞鱼酱① 提交于 2019-12-03 05:15:19
We are working with a rather large model in a EF 6.1 code first setup and we are using ints for entity ids. Unfortunately, this is not as typesafe as we would like, since one can easily mix up ids, for example comparing ids of entities of different types (myblog.Id == somePost.Id) or similar. Or even worse: myBlog.Id++. Therefore, I came up with the idea of using typed ids, so you cannot mix up ids. So we need a BlogId type for our blog entity. Now, the obvious choice would be to use an int wrapped in a struct, but you cannot use structs as keys. And you cannot extend int... - wait, you can!

EF6/Code First: Super slow during the 1st query, but only in Debug

家住魔仙堡 提交于 2019-12-03 04:17:15
问题 I'm using EF6 rc1 with Code First strategy, without precompiled views and the problem is: If I compile and run the exe application it takes like 15 seconds to run the first query (that's okay, since I'm still working on the pre-generated views). But if I use Visual Studio 2013 Preview to Debug the exact same application it takes almost 2 minutes BEFORE running the first query: Dim Context = New MyEntities() Dim Query = From I in Context.Itens '' <--- The debug takes 2 minutes in here Dim Item

update the database from package manager console in code first environment

有些话、适合烂在心里 提交于 2019-12-03 04:16:27
问题 Code First Environment I'm trying to update the database from package Manager console.If my Domain class change, I have to drop and create the database,Instead of dropping the Database how can i update the database. I have already try by reading some blogs in google. commands PM> Install-Package EntityFramework By using this command i install the Entity Framework successfully. PM> Enable-Migrations By using this command it created the Migration file in my project. PM> Update-Database By using

How to use generic type with the database Context in EF6 Code First

百般思念 提交于 2019-12-03 03:42:29
For example, let say I have 4 different entity that each implement a Add() method that add the entity to the database : public class Profile { ... public void Add() { this._dbContext.Profile.Add(this); this._dbContext.SaveChanges(); } ... } Now I would like to have a generic class that implement this kind of behavior in one abstract class instead of X number of classes. So I tried the following : public abstract class Entity<TEntity> where TEntity : class { protected DbContext _dbContext; protected Entity() { this._dbContext = new SMTDBContext(); } public void Add() { this._dbContext.Set

How do I use spatials to search a radius of zip codes?

旧巷老猫 提交于 2019-12-03 03:19:14
Background I'm writing an application which finds events within a certain radius of a zip code. You can think of this like ticketmaster, where you type in your zip code and all of the concerts in the radius of x show up. I have a database table which has the zip code, and each zip codes' Latitude and Longitude. I also have an 'EventListings' table where each 'Event' has a ZipCode field. Problem Currently, I'm using the Haversine formula in a Linq-to-Entities query in my service layer to find which events are within the radius. Right now, I'm using it as a filter in the where clause. I'd also

Possible to set column ordering in Entity Framework

别等时光非礼了梦想. 提交于 2019-12-03 03:18:45
Is there any possible configuration to set database column ordering in entity framework code first approach..? All of my entity set should have some common fields for keeping recordinfo public DateTime CreatedAt { get; set; } public int CreatedBy { get; set; } public DateTime ModifiedAt { get; set; } public int ModifiedBy { get; set; } public bool IsDeleted { get; set; } I want to keep this fields at the end of the table. Is there any possible EF configuration that i can use to config this rather than keeping this fields at the end of my model class. I'm assuming you are using Entity Framework

Thread safe Entity Framework 6

懵懂的女人 提交于 2019-12-03 02:45:40
Just starting testing EF6 and its Async functions. Boy was I surprised when I realized that they are not thread safe. I kinda assumed that that was the point. I had my own Task based extension methods for years already, but what I was waiting for from EF was to make them thread safe. At least my Task based functions lock ed as to not interfere with each other. EF6 doesn't even go that far. But the main problem is something that my code shares with theirs. i.e. Try issuing an async query and then before it completes try accessing a navigation property (on a pre-loaded totally separate entity in

EF6 Code First with generic repository and Dependency Injection and SoC

[亡魂溺海] 提交于 2019-12-03 02:32:54
问题 After a lots of reading and trying things out with Entity Framework latest stable version (6.1.1). I'm reading lots of contradictions about whether or not to use repositories with EF6 or EF in general, because it's DbContext already provides a repository and DbSet the UoW , out of the box. Let me first explain what my solution contains in terms of project and then I'll comeback at the contradiction. It has a class library project, and an asp.net-mvc project. The class lib project being the

EF & Automapper. Update nested collections

£可爱£侵袭症+ 提交于 2019-12-03 02:30:21
I trying to update nested collection (Cities) of Country entity. Just simple enitities and dto's: // EF Models public class Country { public int Id { get; set; } public string Name { get; set; } public virtual ICollection<City> Cities { get; set; } } public class City { public int Id { get; set; } public string Name { get; set; } public int CountryId { get; set; } public int? Population { get; set; } public virtual Country Country { get; set; } } // DTo's public class CountryData : IDTO { public int Id { get; set; } public string Name { get; set; } public virtual ICollection<CityData> Cities {

Entity Framework 6 Cannot build after adding stored procedures to data model

只愿长相守 提交于 2019-12-03 01:02:56
问题 I just downloaded entity framework 6 and created a brand new project to test it. We currently use EF 5. After adding all my tables and stored procedures, I tried to build the project but I get errors: Value of type 'System.Data.Objects.ObjectParameter' cannot be converted to 'System.Data.Entity.Core.Objects.ObjectParameter'. Value of type 'System.Data.Entity.Core.Objects.ObjectResult(Of DataLibrary.MyStoredProc_Result)' cannot be converted to 'System.Data.Objects.ObjectResult(Of DataLibrary