entity-framework-6

Use a variable to call a method

拜拜、爱过 提交于 2020-01-04 09:02:53
问题 I'm using Entity framework to manipulate a data base, and I was wondering if I could used a variable to call a method I tried with this way: string name = "tableName"; db.[name].AddRange(dates.[name]); but it didn't work I want to call a method of this way because I'm going to do multiples inserts in different tables. and I have in mind use an array or some collection with all the names of the tables. and then iterate the collection public ActionResult MetodoRecibe(Reporte datas) { string

Why does Entity Framework generate large parameters? How can they be reduced?

房东的猫 提交于 2020-01-04 05:19:11
问题 In a very simple db query: _service.GetAll<Visitor>().Any(r => r.EmailAddress == email) when tracing this using Glimpse, it shows a parameter @p__linq__0 of Type String and Size 4000 being passed to the database. The following SQL is generated: SELECT CASE WHEN ( EXISTS (SELECT 1 AS [C1] FROM [dbo].[Visitor] AS [Extent1] INNER JOIN [dbo].[VisitorType] AS [Extent2] ON [Extent1].[Id] = [Extent2].[Id] WHERE ([Extent2].[EmailAddress] = 'test@test.com' /* @p__linq__0 */) OR (([Extent2].

Dis-Advantages of using EF 6.x.x Code First without Migration

一笑奈何 提交于 2020-01-03 16:50:06
问题 I am fed up of using/running Add-Migration and Update-Database because lot of time we forget to run migrations on production database. So, we decided to delete all migrations from database table as well all migration classes. So, what if my __MigrationHistory table remains always empty and no migration classes. What is the main disadvantage? 回答1: No this is a bad idea, the [__MigrationHistory] is used to compare your current used conceptual model with the storage model. 1) Case:

Entity Framework 6.1 - SaveChanges fails with Optional Principal relationship

梦想与她 提交于 2020-01-03 06:44:14
问题 I have an entity called Employee . It has a nullable property called CreatedById which is used as a reference back to itself. It has to be null since the very first record, presumably the administrator, won't have a creator. When by database is being initialized, I keep getting an error when the first Employee object is inserted which I presume is because of the way I updated the relationships with the Fluent API. Code is as follows: The Employee class: public class Employee :

Entity Framework 6 - Npgsql - connection string error

邮差的信 提交于 2020-01-03 01:41:13
问题 A tricky (and frustrating problem) - perhaps you folks may be clever enough to solve it: Problem I want to be able to read/write to my database using Entity Frameworks. I have got a simple app rails running on Heroku (straightforward scaffold). I want to connect to this database and manipulate records. The good news is that I can successfully connect to that database using npgsql. The bad news is that I cannot do it with Entity Frameworks. This is the error I’m receiving: System.Data.Entity

Mock Entity Framework long LINQ query

拜拜、爱过 提交于 2020-01-02 14:44:37
问题 Have a LINQ query expression (below) that want to test mocking the Entity Framework. To mock I am using the code: Entity Framework Testing with a Mocking Framework This works for other queries but doesn't work for this var query = from vwPs in _reportingDbContext.VwAccountNumber join ps in _reportingDbContext.PaymentSummary on new { Key1 = vwPs.Id, Key2 = vwPs.AccountNumber, Key3 = true, Key4 = true } equals new { Key1 = ps.Id, Key2 = ps.AccountNumber, Key3 = ps.PaymentDate >= fromDateTime,

Mock Entity Framework long LINQ query

☆樱花仙子☆ 提交于 2020-01-02 14:44:26
问题 Have a LINQ query expression (below) that want to test mocking the Entity Framework. To mock I am using the code: Entity Framework Testing with a Mocking Framework This works for other queries but doesn't work for this var query = from vwPs in _reportingDbContext.VwAccountNumber join ps in _reportingDbContext.PaymentSummary on new { Key1 = vwPs.Id, Key2 = vwPs.AccountNumber, Key3 = true, Key4 = true } equals new { Key1 = ps.Id, Key2 = ps.AccountNumber, Key3 = ps.PaymentDate >= fromDateTime,

Error: “The Id field is required.” while registering new user in database with AspNet.Identity 2.0

孤街浪徒 提交于 2020-01-02 09:58:18
问题 Welcome, I get the validation error mentioned in topic while creating (registering) new user in my Asp.Net mvc application where I used Asp.Net Identity with my custom ApplicationUser class public class ApplicationUser : IdentityUser<string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim> { public async Task<ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager manager) { var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes

What is the best practice of passing data from a controller to a view layout?

一曲冷凌霜 提交于 2020-01-02 09:56:30
问题 I currently have a MVC site that needs to have dynamic content on the header of every page. I currently get the required data as normal in the controller and place it in a View Model. In the view, I take the data and stick the template parts in to the Viewbag and finally, on the main layout page, I take the Viewbag data and pass it to the partial which controls the header. I've read that I shouldn't use Viewbag where possible, and the amount of times I pass the data round just doesn't feel

Entity Framework Code First initializing foreign keys

淺唱寂寞╮ 提交于 2020-01-02 09:42:10
问题 This is how the code looks like: public class Family { public int FamilyID { get; set; } public virtual ICollection<Member> FamilyMembers { get; set; } } public class Member { public int MemberID { get; set; } public virtual Family Family { get; set; } } public class Bicycle { public int BicycleID { get; set; } public virtual Member Owner { get; set; } } public class MyContext : DbContext { public MyContext : base () { } } So, there is a one-to-one relantionship between Member and Bicycle,