entity-framework-6

How do I go about unit testing with Entity Framework and Moq?

流过昼夜 提交于 2019-12-20 15:21:03
问题 I'm new to Moq, and wanting to use it like a backing store for data - but without touching the live database. My setup is as follows: A UnitOfWork contains all repositories, and is used for data access throughout the application. A Repository represents a direct hook into a DbSet, provided by a DbContext. A DbContext contains all DbSets. Here is my test so far: // ARRANGE var user = new User() { FirstName = "Some", LastName = "Guy", EmailAddress = "some.guy@mockymoqmoq.com", }; var mockSet =

Thread safe Entity Framework 6

我与影子孤独终老i 提交于 2019-12-20 11:37:18
问题 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

How to list users with role names in ASP.NET MVC 5

落爺英雄遲暮 提交于 2019-12-20 10:37:48
问题 I have default project template of ASP.NET MVC 5 web site and I am trying to list all users with role names (not IDs). The query is: db.Users.Include(u => u.Roles).ToList() Then I want to print the role names with something like: @string.Join(", ", user.Roles.Select(r => r.RoleId)) The problem is that I can reach only RoleId , not Role class where Name and other properties are stored. I could run another select to get all roles and then use that as a lookup. Or write a join in the query

Entity Framework: The provider did not return a providermanifest instance

泪湿孤枕 提交于 2019-12-20 10:28:11
问题 Entity Framework 6.0.1 my App.config: <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections> <startup> <supportedRuntime version=

Entity Framework query performance differs extrem with raw SQL execution

风格不统一 提交于 2019-12-20 09:15:27
问题 I have a question about Entity Framework query execution performance. Schema : I have a table structure like this: CREATE TABLE [dbo].[DataLogger] ( [ID] [bigint] IDENTITY(1,1) NOT NULL, [ProjectID] [bigint] NULL, CONSTRAINT [PrimaryKey1] PRIMARY KEY CLUSTERED ( [ID] ASC ) ) CREATE TABLE [dbo].[DCDistributionBox] ( [ID] [bigint] IDENTITY(1,1) NOT NULL, [DataLoggerID] [bigint] NOT NULL, CONSTRAINT [PrimaryKey2] PRIMARY KEY CLUSTERED ( [ID] ASC ) ) ALTER TABLE [dbo].[DCDistributionBox] ADD

How to extend an Entity Framework 6.1.3 generated class?

北战南征 提交于 2019-12-20 05:30:21
问题 Is it possible to extend an Entity Framework 6.1.3 generated class? I have an existing database to which I have created an ADO.NET Entity Data Model, which in turn Visual Studio 2015 has generated a set of classes. public partial class WebApplication1Entities : DbContext { public WebApplication1Entities() : base("name=WebApplication1Entities") { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { throw new UnintentionalCodeFirstException(); } } I can manually override the

EF6 with MySQL. The given key was not present in the dictionary

谁说胖子不能爱 提交于 2019-12-20 05:24:04
问题 I have Asp.Net MVC 5 application using Code First Entity Framework 6 linked to MySQL database. When I created the database first time, it works fine. But when I make a change to the model then add migration. An error shows after (Update-Database). This is the error: PM> Update-Database System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at MySql.Data.MySqlClient

The value's length for key 'data source' exceeds it's limit of '128'

社会主义新天地 提交于 2019-12-20 05:11:13
问题 I know that a very similar question has been asked here, but the answer didn't help me. I am using Entity Framework 6 with the Oracle.ManagerDataAccess.Client. If I define the connection string in app.config, then the connection works. If I specify the identical connection string in code, then I get the error The value's length for key 'data source' exceeds it's limit of '128'. which is correct. This is my connection string (with some names removed): "User Id=xxxxxxxxxxx;Password=xxxx;Data

Prevent EF6 from generate navigation properties

▼魔方 西西 提交于 2019-12-20 05:01:07
问题 I've recently started to use EF6 and i'm building a couple of T4 templates to generate some code automatically (on VS2012). I'm generating my model from the database and this process creates all the associations automatically based on the DB ForeignKeys. And generates too a "Navigation Property" for that field in Associations/FK. I want to get a "Flat Version" of my entities without navigation properties. Just a class with properties corresponding to table columns. Is there any way to

How to link one-to-one relationship when fk is different from pk - EntityFramework

假装没事ソ 提交于 2019-12-20 04:59:08
问题 I have a custom users table in my database and i want to create a one-to-one relationship with aspnetusers table so that when i register a new customer, applicationuser class through UserManager should add the username, email, password and school code to the users table and add an fk in its own table. IS there any tutorial/example implementing this kind of scenario? I am trying to add a one-to-one relationship with my users table but the fk is different than pk Users Table [columns] username