entity-framework

Entity Framework and OFFSET/FETCH on Sql Server

半世苍凉 提交于 2020-01-11 10:36:13
问题 I just encountered a weird bug in my app where a paged data grid contained duplicate rows. Investigation showed that it's because the new paging mechanism Entity Framework uses with Sql Server 2012 as of version 6.1.2 only works on strictly ordered column sets , as is documented here. Since most columns are not strictly ordered (meaning you have duplicate entries with respect to the sort order), simply binding one of the typical grid middlewares to Entity Framework is now broken subtly and

Enity Framework overriding identity column

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-11 10:06:09
问题 I have a Code First EF class like so: public class Event { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int ID { get; set; } /* snip */ } and what I want to happen is when the ID property is null or 0 the database will generate an ID value for it, however if I explicitly set this value so newEvent.ID=10000000 , it will use that as the ID column, currently doing that will result in the next available ID. 回答1: To start, I am not aware of a good solution for this.

Enity Framework overriding identity column

故事扮演 提交于 2020-01-11 10:06:08
问题 I have a Code First EF class like so: public class Event { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int ID { get; set; } /* snip */ } and what I want to happen is when the ID property is null or 0 the database will generate an ID value for it, however if I explicitly set this value so newEvent.ID=10000000 , it will use that as the ID column, currently doing that will result in the next available ID. 回答1: To start, I am not aware of a good solution for this.

How do SQL Server computed columns work in EntityFramework?

Deadly 提交于 2020-01-11 09:51:32
问题 I have a table whose column TotalAmount is a computed column from columns Amount+Extra , so how this computation works, if I use Entity Framework on this table? Thanks. 回答1: A computed column is either (a) recalculated every time you access it, or (b) if you defined it with the PERSISTED keyword, an actual column is created in your table's data pages and the value is stored there. In any way, to Entity Framework, both kinds of computed columns should behave just like regular columns. If

How do I create an association between these 2 entities without touching the DB?

China☆狼群 提交于 2020-01-11 09:21:35
问题 I need to create a "virtual" association between these two entities (1-*) so that I can traverse them using linq , but the problem is I cannot touch the database. I have tried to manually edit the edmx many times without success, getting various mapping errors. EDMX: <?xml version="1.0" encoding="utf-8"?> <edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx"> <!-- EF Runtime content --> <edmx:Runtime> <!-- SSDL content --> <edmx:StorageModels> <Schema Namespace=

ADO.NET provider with invariant name 'System.Data.SqlClient;' cannot be found (Entity Framework MVC)

老子叫甜甜 提交于 2020-01-11 09:19:47
问题 I cannot seem to resolve what appears to be a common issue with Entity Framework 6. I have reviewed the many topics related to this issue on SO, and am unable to find a solution that works for my particular case. I have up until this point been developing using localdb with code first migrations, which worked fine. But now that I am moving this to a actual SQL server instance it throws the following error while attempting migrations: "The ADO.NET provider with invariant name 'System.Data

ASP.NET Identity's UserManager caches users?

[亡魂溺海] 提交于 2020-01-11 09:12:48
问题 We're using ASP.NET Identity 2.2 with ASP.NET MVC 5.2, Entity Framework 6.2 and Unity 5.7. We have a class, ConnectUserManager , that derives from ASP.NET Identity's UserManager . A newly constructed UserStore is passed to UserManager every time. The lifetime of ConnectUserManager (and thus of UserManager ) is per request: Container.RegisterType<ConnectUserManager>( new PerRequestLifetimeManager(), new InjectionConstructor( Container.Resolve<ConnectDbContext>(), Container.Resolve

Multiple .Where() clauses on an Entity Framework Queryable

送分小仙女□ 提交于 2020-01-11 08:34:10
问题 I am trying to implement a complex filter using Entity Framework: I want to add where clauses to the queryable object based on my provided search criteria. Can I do the following in Entity Framework 6? var queryable = db.Users.Where(x => x.Enabled && !x.Deleted); // Filter var userId = User.Identity.GetUserId(); queryable.Where(x => x.AspNetUser.Id == userId); queryable.Where(x => x.Status >= 2); // ...etc I know that I can do: var queryable = db.Users .Where(x => x.Enabled && !x.Deleted)

Should I Treat Entity Framework as an Unmanaged Resource?

大憨熊 提交于 2020-01-11 08:29:05
问题 I am working with a class that uses a reference to EF in its constructor. I have implemented IDisposable , but I'm not sure if I need a destructor because I'm not certain I can classify EF as an unmanaged resource. If EF is a managed resource, then I don't need a destructor, so I think this is a proper example: public ExampleClass : IDisposable { public ExampleClass(string connectionStringName, ILogger log) { //... Db = new Entities(connectionStringName); } private bool _isDisposed; public

How to drop a table in Entity Framework Code First?

 ̄綄美尐妖づ 提交于 2020-01-11 08:22:28
问题 I am using Entity Framework with Auto Migrations. So when I add a new model to my Context, my database is updated and new table is created. What I want to do is the opposite, droping the table completely from database. However, removing the definition from Context class does not work. public class CompanyContext : DbContext { public DbSet<Permission> Permissions { get; set; } public DbSet<Company> Companies { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) {