entity-framework-6

Is it really impossible to update child collection in EF out of the box (aka non-hacky way)?

南楼画角 提交于 2019-11-30 18:23:24
Let's say you have these classes in your entities. public class Parent { public int ParentID { get; set; } public virtual ICollection<Child> Children { get; set; } } public class Child { public int ChildID { get; set; } public int ParentID { get; set; } public virtual Parent Parent { get; set; } } And you have a user interface to update the Parent along with its Children , meaning if the user add new Child then you have to insert, if the user edits an existing Child then you need to update, and if the user removes a Child then you have to delete. Now obviously if you use the following code

entity framework execute SQL before migrations

倾然丶 夕夏残阳落幕 提交于 2019-11-30 18:00:57
I am working on an existing project that uses Entity-Framework 6 with code-first. I have a need to run some SQL before the migrations run. I have a DbMigrationsConfiguration class with a seed method, but seed runs after the migrations. I think it will work if I run my SQL in the constructor but I can't get a reference to the context. Does anyone know how to do this? You could use the 'Sql' method within the desired migration class. public partial class OneOfYourMigrations : DbMigration { public override void Up() { //EF generated migration code here such as //CreateTable or AddColumn etc... /

Scaffolding controllers with repositories in Mvc5, EF6, VisualStudio 2013

二次信任 提交于 2019-11-30 17:41:15
In vs2012 I used to use Steve Sanderson's mvcScaffolding Package with this package I could scaffold Action Methods with unit tests and controllers with repositories and dependency injection. My question is simple. Is there a way to do so in vs2013? When I install the package in vs2013 I get the following errors: Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE At C:\dev\WebApplication2\packages\T4Scaffolding.Core.1.0.0\tools\init.ps1:50 char:9 + Set-DefaultScaffolder -Name CustomTemplate -Scaffolder T4Scaffolding.Cus ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Using SqlQuery to get IQueryable

社会主义新天地 提交于 2019-11-30 17:25:05
Is there something that can return IQueryable for a dynamic sql query in Entity Framework 6? This is what I am using now but it is pulling all the records (as expected). DbContext.Database.SqlQuery<T>("SELECT * FROM dbo.SomeDynamicView") Problem is that SqlQuery returns DbRawSqlQuery which is IEnumerable . dbo.SomeDynamicView is a database view created at runtime. Scott Chamberlain No, you can't get a IQueryable from SqlQuery * , this is because what IQueryable is doing is building a SQL string dynamically based on what select and where filters you put in. Because in SqlQuery you are providing

Change table name at runtime

核能气质少年 提交于 2019-11-30 16:23:33
Lets suppose that I have a db table with name Employee and a respective EF 6.0 db-first model. Getting all rows of table Employee is done through query: context.Employees.ToList() Is it possible, at runtime and on demand, to redirect the db table name to Test1 while using the same object name and query? Maybe a case for EF 6.0 Interceptor usage? I know it's been been a while since the original post, but I'll add my answer to help someone else. I had generic SQL queue tables with different table names. I.e. the schema is exactly the same for both tables. I created a framework so that you can

Change table name at runtime

拟墨画扇 提交于 2019-11-30 16:16:51
问题 Lets suppose that I have a db table with name Employee and a respective EF 6.0 db-first model. Getting all rows of table Employee is done through query: context.Employees.ToList() Is it possible, at runtime and on demand, to redirect the db table name to Test1 while using the same object name and query? Maybe a case for EF 6.0 Interceptor usage? 回答1: I know it's been been a while since the original post, but I'll add my answer to help someone else. I had generic SQL queue tables with

UserId not found error in aspnet Identity at GenerateUserIdentityAsync method

自作多情 提交于 2019-11-30 16:16:32
问题 I am getting UserId not found error after registring a user and also after login.Moreoever, after registration, data is saved to database and in dbo.AspNetUsers table, id column is auto incremented and return type is int. There is UserId Column in AspNetUserClaims table.It has 4 Col---Id,UserId,ClaimType,ClaimValue.It has Id column as auto incremented not the userId. I was initially successfully changed Primary key from string to int by following this link---http://www.asp.net/identity

How to map an int to its enum description using AutoMapper during a queryable projection?

为君一笑 提交于 2019-11-30 16:15:16
问题 Here is the enum extension method to get its description attribute. public static string GetDescription(this Enum enumeration) { if (enumeration == null) throw new ArgumentNullException(); var value = enumeration.ToString(); var type = enumeration.GetType(); var descriptionAttribute = (DescriptionAttribute[]) type.GetField(value).GetCustomAttributes(typeof (DescriptionAttribute), false); return descriptionAttribute.Length > 0 ? descriptionAttribute[0].Description : value; } Here is the source

UserId not found error in aspnet Identity at GenerateUserIdentityAsync method

会有一股神秘感。 提交于 2019-11-30 15:59:24
I am getting UserId not found error after registring a user and also after login.Moreoever, after registration, data is saved to database and in dbo.AspNetUsers table, id column is auto incremented and return type is int. There is UserId Column in AspNetUserClaims table.It has 4 Col---Id,UserId,ClaimType,ClaimValue.It has Id column as auto incremented not the userId. I was initially successfully changed Primary key from string to int by following this link--- http://www.asp.net/identity/overview/extensibility/change-primary-key-for-users-in-aspnet-identity . It was running succesfully before

UserManager.Create(user, password) thowing EntityValidationError saying Id is required?

你离开我真会死。 提交于 2019-11-30 15:46:57
问题 Anybody know why UserManager.Create(user, password); might be throwing EntityValidationError saying Id is required. Could it have something to do with my UserManager . It is setup like this: public class MyAppDb : IdentityDbContext<ApplicationUser, ApplicationRole, string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim> { public static MyAppDb Create() { return new MyAppDb(); } public MyAppDb() : base("MyAppDb") { } } public class ApplicationUserStore : UserStore