entity-framework-6

Asp.Net Identity - IdentityDbContext<TUser> causing problems for fields added to AspNetRoles table

南楼画角 提交于 2019-12-12 04:41:06
问题 IdentityDbContext causing problems for properties/fields added to AspNetRoles I believe the problem is here with IdentityDbContext taking an IdentityUser type: public class MyIdentityDb : IdentityDbContext<ApplicationUser> { public IdentityDb() : base("IdentityDb") { } } But let me explain… It is wonderful that we can add fields to the AspNetUsers table by adding properties to our ApplicationUser class that inherits from IdentityUser. Example: public class ApplicationUser : IdentityUser {

Unable to cast object of type 'DBContext.Models.Contact' to type 'System.Data.Entity.Infrastructure.IObjectContextAdapter'

独自空忆成欢 提交于 2019-12-12 04:34:53
问题 I am trying to implement "Repository-Pattern" and "Edit" method in Contact-Controller is making use of "Attach Method" in Contact-Repository is throwing Error. Additional information: Unable to cast object of type 'Contacts.Models.Contact' to type 'System.Data.Entity.Infrastructure.IObjectContextAdapter'. Before This issue i faced another issue of ObjectStateManger Extension not found error in the code : entities.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified); So i had to

how can I add a new row to datagrid at every button click in winform

我是研究僧i 提交于 2019-12-12 04:31:58
问题 I want to add new row to gridcontrol at every button click. I tried many ways but no success. I am sending my code. private void B_Click(object sender, EventArgs e) { Button bt = (Button)sender; int productId = (int)bt.Tag; AddProductDataContext db = new AddProductDataContext(); decimal Quantity; decimal.TryParse(txtCalculator.Text, out Quantity); gridControl1.DataSource = from inv in db.Inventories where inv.RecId == productId select new { inventoryName = inv.InventoryName, Quantity, Total =

Why mapping is not working using Entity Framework in visual studio 2015 professional

杀马特。学长 韩版系。学妹 提交于 2019-12-12 04:22:36
问题 I have created a context of Entity Framework like below: using System; using System.Data.Entity; using System.Data.Entity.ModelConfiguration.Conventions; using System.Collections.Generic; using System.Linq; using System.Web; namespace UniversityApp.Models { public class ProfDb : DbContext { public DbSet<Professor> Professors { get; set; } public DbSet<Student> Students { get; set; } } } I am using VS 2015 Professional. Then I go to View=>Server Explorer=> Add Connection=> Microsoft Sql Server

Multiple identity columns specified for table exception [duplicate]

二次信任 提交于 2019-12-12 03:55:48
问题 This question already has answers here : Cant remove identity attribute from PK (2 answers) Closed 3 years ago . I have this initial migration: namespace DataAccess.Migrations { using System.Data.Entity.Migrations; public partial class init : DbMigration { public override void Up() { CreateTable( "dbo.SchoolclassCodes", c => new { Schoolclass = c.Int(nullable: false, identity: true), Type = c.String(), }) .PrimaryKey(t => t.Schoolclass); } public override void Down() { DropTable("dbo

Add stored procedure to Entity Framework [duplicate]

℡╲_俬逩灬. 提交于 2019-12-12 03:51:03
问题 This question already has answers here : EF4 - The selected stored procedure returns no columns (13 answers) Closed 3 years ago . I have a stored procedure which generate itself dynamically, in detail I am adding to where, order by clauses dynamically. Here is my stored procedure: ALTER PROCEDURE [dbo].[sp_GetConsultants] @SearchQuery VARCHAR(MAX) = NULL, @SortDataField VARCHAR(100), @SortOrder VARCHAR(4), @PageNum INT, @PageSize INT, @sql NVARCHAR(MAX) = NULL OUTPUT AS BEGIN SET @sql = N'

how can i write a generic query with EF and C#

风流意气都作罢 提交于 2019-12-12 03:46:58
问题 i want to write a query in entity framework like this: T entity = (from e in myContext.typeof(T) ) i tried to use string concat but this dose not work for get a member from myContext more code: public T GetEntity<T>(Guid entityId, string connectionString) { using (RContext rpContext = new RContext(connectionString)) { var entity = (from e in rpContext.Set<T>() where e.Id == entityId select e).FirstOrDefault(); return (T) Convert.ChangeType(entity, typeof(T)); } } 回答1: You can access the

Entity Framework - Many to many with shared foreign key

三世轮回 提交于 2019-12-12 03:43:13
问题 I would like my Business and Customer tables to both reference the same Address table, so I created a many to many relationship table "EntityAddress" My EntityAddress table has a EntityID field that I want the Business and Customer tables to share. However when I run my code below, my EntityAddress table has BusinessId and CustomerId fields that are auto-created. Any idea why this is happening? Thanks!! builder.Entity<EntityAddress>().HasKey(x => new { x.EntityId, x.AddressId }); builder

TransactionScope with EntityFramework 6 and MySql

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 03:23:05
问题 I have the following requirement for a project: preform transactions over multiple databases in MySql with EntityFramework (all databases are on the same mysql server). When trying to solve the issue with TransactionScope, there seems to be an issue with different MySql connection strings: "Multiple simultaneous connections or connections with different connection strings inside the same transaction are not currently supported." The issue is already described here (without any concrete

Entity Framework not updating existing related entity

别说谁变了你拦得住时间么 提交于 2019-12-12 02:59:51
问题 I have a project which uses Entity Framework extensively. And it all works fine. However, there is one update that I am trying to make and it does not update, nor is an error thrown. The basic process is that I take an existing entity, work with it to create a new (and different type) of entity. The new entity saves just fine, but the existing one does not. Typically when I have encountered this, it means that the entity is not attached to the context. However, it is, and I have tried