entity-framework-6.1

Find method not working with EF6.1 mock

半城伤御伤魂 提交于 2021-02-17 03:59:07
问题 I've setup mocking using these msdn guidlelines: Testing with a mocking framework (EF6 onwards) var bsAc = _db.BusAcnts.FirstOrDefault(i => i.Id == 1); returns an account but var bsAc = _db.BusAcnts.Find(1); returns null when mocked. Find only fails when testing with a mock, it works fine in production. BusAcnt: (Id is the Primary Key) public class BusAcnt { public int Id { get; set; } ... } See the rest of my setup here. In debug I drilled down into Locals | this | MyDbContext and all the

Find method not working with EF6.1 mock

二次信任 提交于 2021-02-17 03:54:51
问题 I've setup mocking using these msdn guidlelines: Testing with a mocking framework (EF6 onwards) var bsAc = _db.BusAcnts.FirstOrDefault(i => i.Id == 1); returns an account but var bsAc = _db.BusAcnts.Find(1); returns null when mocked. Find only fails when testing with a mock, it works fine in production. BusAcnt: (Id is the Primary Key) public class BusAcnt { public int Id { get; set; } ... } See the rest of my setup here. In debug I drilled down into Locals | this | MyDbContext and all the

EF 6.1 Index IsUnique not being generated

末鹿安然 提交于 2020-03-02 07:22:23
问题 I have the following code first entity: class Role { [Key] public int Id { get; set; } [Index("NameIndex", IsUnique = true)] public string Name { get; set; } } But on checking the database with SQL Management Studio, there are multiple rows of the same name: ID=1, Name=admin ID=2, Name=admin My context is very simple: class MemberContext : DbContext { public DbSet<User> Users { get; set; } public DbSet<Role> Roles { get; set; } } Checking the SQL 2014 Express database table indexes, none are

How to retrieve user details from database and display in a view [MVC 5 application,,Identity User]

白昼怎懂夜的黑 提交于 2020-01-17 02:20:12
问题 I just started creating an mvc 5 application ,I'm using default Identity user database for user data management,But I added some more fields like First Name ,Last Name ,Email Id to this database using migration,Now I need to display this all detail in a view page (as a profile page) ,but I don't know how to retrieve Identity user data from default database ,I am a new mvc developer can you help me my model class namespace WebApp.Models { public class ExternalLoginConfirmationViewModel {

Entity Framework 6: is there a way to iterate through a table without holding each row in memory

牧云@^-^@ 提交于 2020-01-11 02:06:46
问题 I would like to be able to iterate through every row in an entity table without holding every row in memory. This is a read only operation and every row can be discarded after being processed. If there is a way to discard the row after processing that would be fine. I know that this can be achieved using a DataReader (which is outside the scope of EF), but can it be achieved within EF? Or is there a way to obtain a DataReader from within EF without directly using SQL? More detailed example:

Mocking Entity Framework 6 ObjectResult with Moq

不打扰是莪最后的温柔 提交于 2020-01-04 18:14:40
问题 How can I mock the Entity Framework 6 ObjectResult with Moq so that I can unit test my code that relies on an EF database connection? Having read numerous questions and answers along these lines, and gleaned many nuggets from what I've read, I've implemented what I feel is a reasonably elegant solution and felt that I should share it, since the community here helped me get there. Thus, I'll proceed to answer this question, and potentially open myself up to some mockery (pun intended): 回答1:

Mocking Entity Framework 6 ObjectResult with Moq

白昼怎懂夜的黑 提交于 2020-01-04 18:13:27
问题 How can I mock the Entity Framework 6 ObjectResult with Moq so that I can unit test my code that relies on an EF database connection? Having read numerous questions and answers along these lines, and gleaned many nuggets from what I've read, I've implemented what I feel is a reasonably elegant solution and felt that I should share it, since the community here helped me get there. Thus, I'll proceed to answer this question, and potentially open myself up to some mockery (pun intended): 回答1:

DbMigration.AlterstoredProcedure (Entity Framework migration): How to represent type smallmoney?

只愿长相守 提交于 2020-01-04 13:28:52
问题 In Entity Framework 6.1, in a C# code-based migration (using System.Data.Entity.Migrations.DbMigration), when altering a stored procedure definition using the DbMigration.AlterStoredProcedure method, what's the proper syntax for adding or modifying a stored procedure parameter of the smallmoney type (on SQL Server 2012)? For example, if I have a migration method that modifies an existing SQL Server stored procedure which takes three parameters, of type int , varchar , and smallmoney

Moq Mocking with Identity 2.0 Database

给你一囗甜甜゛ 提交于 2020-01-01 12:06:09
问题 I successfully set up an Integration Test using mocking with Moq against my BusAct controller in an MVC 5, Entity Framework 6 app based on a Simple membership database. But now I have migrated the database to Identity 2.0 and replaced the UserProfile with ApplicationUser. IdentityDbContext: (Modified from Simple membership DbContext) public class MyDb : IdentityDbContext<ApplicationUser> // DbContext { public MyDb () : base("MyApplication") { } // public virtual DbSet<UserProfile>

Entity Framework 6.1.1 Naming Convention for indexes

心不动则不痛 提交于 2020-01-01 11:55:26
问题 I understand how to add conventions to the code first (with migrations) project. I have successfully managed to perform the table names and even changed GUID Id fields to non-clustered. But I have not found how to change the default index name that EF supplies when no name is given. [Index(IsUnique = true)] public string Code { get; set; } [Index] public string Description { get; set; } I have these two requirements. The top index should be named UX_[schema]_[table]_Code , the second IX_