entity-framework-6

MVC5: UserManager.AddToRole(): “Error Adding User to Role: UserId not found”?

久未见 提交于 2019-12-18 11:04:45
问题 I have been experimenting with MVC5/EF6 and trying out the new Identity Authentication with Code-First Migrations. Everything in the solution is currently building and I can add a Migration , but when I perform an update-database through the package manager console in VS2013, my Configuration.cs file fails to fully process my test data into my Tables and outputs Error Adding User to Role: UserId not found . I have tried explicitly setting a User ID and leaving it to be generated by the

How can I use use Entity Framework to do a MERGE when I don't know if the record exists?

让人想犯罪 __ 提交于 2019-12-18 10:48:18
问题 In this SO answer about Entity Framework and MERGE, the example for how to code it is this: public void SaveOrUpdate(MyEntity entity) { if (entity.Id == 0) { context.MyEntities.AddObject(entity); } else { context.MyEntities.Attach(entity); context.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified); } } This assumes that you already know if the entity that you want to upsert exists or not; in this case you check entity.Id . But what if you don't know if the item exists or not?

EF 6 database first: How to update stored procedures?

邮差的信 提交于 2019-12-18 10:27:34
问题 We are using Entity Framework 6.0.0 and use database first (like this) to generate code from tables and stored procedures. This seems to work great, except that changes in stored procedures are not reflected when updating or refreshing the model. Adding a column to a table is reflected, but not adding a field to a stored procedure. It is interesting that if I go to the Model Browser , right click the stored procedure, select Add Function Import and click the button Get Column Information we

EF 6 database first: How to update stored procedures?

本小妞迷上赌 提交于 2019-12-18 10:27:20
问题 We are using Entity Framework 6.0.0 and use database first (like this) to generate code from tables and stored procedures. This seems to work great, except that changes in stored procedures are not reflected when updating or refreshing the model. Adding a column to a table is reflected, but not adding a field to a stored procedure. It is interesting that if I go to the Model Browser , right click the stored procedure, select Add Function Import and click the button Get Column Information we

How to sync model after using Code First from Database using Entity Framework 6.1 and MVC 5?

半腔热情 提交于 2019-12-18 10:03:18
问题 Assumptions Using EF 6.1, MVC 5, VS 2013, C# I have an existing database model designed in Toad DM for SQL Server and it's very important keep it always updated Steps and Notes Using ADO.NET Entity Data Model I chose Code First from Database ( new feature in EF 6.1 ) to generate the models. Note: Model classes and DbContext class generated successfuly but NO .edmx or .tt file was generated . Next I added a new scaffold item: MVC 5 Controllers with views, using Entity Framework. Note: Success,

Sql Stored proc and Entity framework 6

こ雲淡風輕ζ 提交于 2019-12-18 09:14:13
问题 Suppose i have a one parameter stored procedure : procedure dbo.MyStoredProc @param VARCHAR(50) as SELECT * FROM whatever WHERE column = @param In my web application (mvc with entity 6 ) i wish to call my stored procedure, and retreive all the line from it's SELECT statement. var DBLines = MyStoredProc(parameterValue); I saw something disappointing but very logic; my var was containing an integer. That integer was 1. It was telling me that everything went ok in my stored procedure... I want

entity framework 6 - check if record exists before insert and concurrency

喜你入骨 提交于 2019-12-18 07:51:47
问题 I have the following scenario: A business logic function that uses ef6 checks if a record already exists. If the record does not exists, it is inserted on the database. Something like this if (!product.Skus.Any(s => s.SkuCodeGroup == productInfo.SkuCodeGroup && s.SkuCode == productInfo.SkuCode)) AddProductSku(); I have multiple threads calling this business logic function. What happens is: If the function is called simultaneous with the same parameters, both instances checks if the record

How can I get the parameters of an Entity Framework query?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-18 07:12:32
问题 If I create a query of IQueryable<T> , I can call .ToString() to get the SQL that will be called, but that SQL may contain parameters like @p__linq__0, @p__linq__1, etc. Is there a way to get those parameters and their values from the IQueryable<T> 回答1: It's frustratingly complicated, in my experience, but this code got me there: var dbQuery = (DbQuery<T>)query; // get the IInternalQuery internal variable from the DbQuery object var iqProp = dbQuery.GetType().GetProperty("InternalQuery",

How can I get the parameters of an Entity Framework query?

拟墨画扇 提交于 2019-12-18 07:12:21
问题 If I create a query of IQueryable<T> , I can call .ToString() to get the SQL that will be called, but that SQL may contain parameters like @p__linq__0, @p__linq__1, etc. Is there a way to get those parameters and their values from the IQueryable<T> 回答1: It's frustratingly complicated, in my experience, but this code got me there: var dbQuery = (DbQuery<T>)query; // get the IInternalQuery internal variable from the DbQuery object var iqProp = dbQuery.GetType().GetProperty("InternalQuery",

How do I add an additional column to the __MigrationHistory table?

随声附和 提交于 2019-12-18 07:03:32
问题 Per Customizing the Migrations History Table, I should be able to add a column, however I'm not able to find any examples on how to actually add the new column. I'm mostly confused about where to put the actual property and how to configure it to the existing __MigrationHistory table. From the documentation, I can customize the table configuration like so.. protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity<HistoryRow