entity-framework-6

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

人盡茶涼 提交于 2019-11-30 14:42:56
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<ApplicationUser, ApplicationRole, string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim> { public

postgresql does not appear in Data Source when generating .ADO.net Entity Data Model

ぃ、小莉子 提交于 2019-11-30 14:19:35
I succeeded in accessing an existing postgresql dbase by using npgsql directly. I used for this: PostgreSQL 9.0.10 (32 bit) Visual Studio 2015 Community (64 bit) NpgSql 2.2.5 (through Manage Nuget Packages) The dbase however has 25+ tables and 400+ columns and such my intention is to to use entity framework + .ADO.net Entity Data Model to avoid having to code access to all columns. I searched and tried everything on this site, npgsql site http://www.npgsql.org/doc/ddex.html , ... but I I did not succeeded in generating an .ADO.net Entity Data Model because postgresql does not appear in Data

In Entity Framework 6.1 (not Core), how can I use the IndexAttribute to define a clustered index?

倖福魔咒の 提交于 2019-11-30 13:43:23
问题 Entity Framework 6.1 (code-first) has added the possibility of adding indexes via the IndexAttribute . The attribute takes a parameter for specifying whether the index should be clustered or non-clustered. At the same time, AFAIK, Entity Framework requires every entity to have a primary key (annotated with the KeyAttribute ), and that primary key is always created as a clustered key. Therefore, as soon as I apply the IndexAttribute with IsClustered = true , I get an error because, due to the

EntityFramework CodeFirst: CASCADE DELETE for same table many-to-many relationship

☆樱花仙子☆ 提交于 2019-11-30 12:41:21
I have an entry removal problem with the EntityFramework and a many-to-many relationship for the same entity. Consider this simple example: Entity: public class UserEntity { // ... public virtual Collection<UserEntity> Friends { get; set; } } Fluent API Configuration: modelBuilder.Entity<UserEntity>() .HasMany(u => u.Friends) .WithMany() .Map(m => { m.MapLeftKey("UserId"); m.MapRightKey("FriendId"); m.ToTable("FriendshipRelation"); }); Am I correct, that it is not possible to define the Cascade Delete in Fluent API? What is the best way to delete a UserEntity , for instance Foo ? It looks for

Using TransactionScope with Entity Framework 6

非 Y 不嫁゛ 提交于 2019-11-30 11:57:49
问题 What I can't understand is if its possible to make changes to the context and get the changes in the same transaction before its commited. This is what I´m looking for: using (var scope = new TransactionScope(TransactionScopeOption.Required)) { using (var context = new DbContext()) { //first I want to update an item in the context, not to the db Item thisItem = context.Items.First(); thisItem.Name = "Update name"; context.SaveChanges(); //Save change to this context //then I want to do a

Does anyone have a very complete example generic repository for EF 6.1?

[亡魂溺海] 提交于 2019-11-30 11:39:29
问题 I have my own repository that is as follows. However this does not take into account some of the new features such as the range features. Does anyone have a repository that includes everything. I have searched for this on the net but there's nothing that I can find that is recent. Here is what I have. I am hoping for something that has more and that offers IQueryable for many of the methods: namespace Services.Repositories { /// <summary> /// The EF-dependent, generic repository for data

When is the Seed method called in a EF code first migrations scenario?

自古美人都是妖i 提交于 2019-11-30 11:05:14
I'm new in a project and there is this class for the seed data: internal sealed class Configuration : DbMigrationsConfiguration<DAL.Context> { public Configuration() { AutomaticMigrationsEnabled = true; } And this code to start the seed: protected override void Seed(Context context) { try { My question is: when is the Seed method called? Only when a user does update-database and the user doesn't have the database (basicly a new user), or also when the user with an existing database calls an update-database ? Seed method is used to initialized the database tables with some starting data.

Why is UserManager.CreateIdentityAsync() looking for IdentityRole and how to fix?

五迷三道 提交于 2019-11-30 10:03:25
I'm using Identity2.0 with MVC5 CodeFirst I have extended both the IdentityUser and IdentityRole like this: public class ApplicationUser : IdentityUser { [Required] [StringLength(50)] public string FirstName { get; set; } [Required] [StringLength(50)] public string LastName { get; set; } } public class ApplicationRole : IdentityRole { [Required] [StringLength(50)] public string ProperName { get; set; } [Required] public string Description { get; set; } } public class MyAppDb : IdentityDbContext<ApplicationUser, ApplicationRole, string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim> {

Get SQL file for specific migration in Entity Framework 6 C#

最后都变了- 提交于 2019-11-30 09:17:33
In Entity Framework 6, I need to get the SQL script for specific migration file and I already update the database. I found that in update-database command I can add script parameter to export it to SQL but I already updated the database. I found in Entity Framework Core, a command called Script-Migration with script name as an argument. Is there any similar command in Entity framework? i also i tried the below, and i got empty SQL file Update database command Yes, you could do like followed: Update-Database -Script -SourceMigration: <pointFromWichYouWantToStartWithGeneration> -TargetMigration:

Entity Framework 6: How to override SQL generator?

醉酒当歌 提交于 2019-11-30 08:49:20
I'd like to amend the SQL that's being generated by EF:CF when generating the database schema (DDL), as suggested by the Entity Framework team . How can this be done? I couldn't find anything appropriate via Google. You can override the MigrationSqlGenerator that is used by Entity Framework by calling the DbMigrationsConfiguration.SetSqlGenerator() method in the constructor of your DbMigrationsConfiguration class, passing the database provider name (e.g. "System.Data.SqlClient" for SQL Server), and the MigrationSqlGenerator instance to use for that database provider. Consider the example from