entity-framework-6

How do I Cascade a SoftDelete?

倖福魔咒の 提交于 2019-12-23 12:50:05
问题 After checking these SO articles: cascade-delete-in-entity-framework, ef6-1-soft-delete-with-cascade-delete, cascading-soft-delete, method-for-cascading-soft-deletes-in-parent-child-relationships and reasons-for-cascading-soft-deletes and not finding a solution... I have SoftDelete working for my Entity Models. I have overridden SaveChanges() in my Context: public override int SaveChanges() { ChangeTracker.DetectChanges(); foreach (DbEntityEntry<ISoftDeletable> entity in ChangeTracker.Entries

Schema specified is not valid. Errors: Multiple types with the name

白昼怎懂夜的黑 提交于 2019-12-23 12:25:10
问题 I am working in EF 6 and facing the following issue when I try run my project. Schema specified is not valid. Errors: Multiple types with the name 'TableName' exist in the EdmItemCollection in different namespaces. Convention based mapping requires unique names without regard to namespace in the EdmItemCollection. I tried too much on StackOverFlow and google and found no solution. I am using visual studio 2012. I crated a single .edmx file for whole of my database. I searched the tableName

EF6 - Cannot Mock Return Value for ObjectResult<T> for Unit Test

十年热恋 提交于 2019-12-23 12:18:20
问题 I have code similar to this in a method that I'm trying to unit test: return _context.usp_get_Some_Data(someStringParam).FirstOrDefault(); The stored proc call return type: ObjectResult<usp_get_Some_Data_Result>. In my unit test, I'm trying to do something like this (using NUnit and Moq): var procResult = new ObjectResult<usp_get_Some_Data_Result>(); mockContext.Setup(m => m.usp_get_Some_Data(It.IsAny<string>())) .Returns(procResult); However, I'm not able to create an instance of

How to only load certain fields of a child object in Entity Framework 6.1?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 11:15:07
问题 I'm working on a model that has two classes, Product and Transaction . public class Product { [DataMember] public Guid ProductId {get; set;} [DataMember] public virtual ICollection<Transaction> Transactions { get; set; } } public class Transaction { [DataMember] public Guid TransactionId {get; set;} [DataMember] public DateTimeOffset Date { get; set; } [DataMember] public String Customer { get; set; } } How do I do a query that will retrieve a product and the Date of its transactions? I tried

How do I add a controller to ASP.NET MVC with Visual Studio 2013 and Entity Framework?

爷,独闯天下 提交于 2019-12-23 10:22:37
问题 I am getting an error when I add a controller in Visual Studio 2013 with ASP.NET MVC 5.0 and Entity Framework 6.0. I have already added a few controllers and generated views but after I added the datatables package, I am getting this type of error: Error "There was an error running the selected code generator" "There was an error getting the type 'project.classes.StudentClass' Try rebuilding the project" I have cleaned and rebuilt the project but it still isn't working. There is a table named

Database applies ALL previous migrations on update and NOT just the new one

烂漫一生 提交于 2019-12-23 09:47:01
问题 I'm developing a website which, as of current, both has a production and a test database. The production database is hosted externally while the test database is hosted locally. Whenever I make changes to my database I apply the changes through a migration. After having added a new migration I run the update-database command on both my production and test database to keep them in sync. I applied the migration just fine to my production database, however, when I wanna apply the migration to my

Database applies ALL previous migrations on update and NOT just the new one

安稳与你 提交于 2019-12-23 09:46:25
问题 I'm developing a website which, as of current, both has a production and a test database. The production database is hosted externally while the test database is hosted locally. Whenever I make changes to my database I apply the changes through a migration. After having added a new migration I run the update-database command on both my production and test database to keep them in sync. I applied the migration just fine to my production database, however, when I wanna apply the migration to my

[Win32Exception (0x80004005): The system cannot find the file specified]

早过忘川 提交于 2019-12-23 09:08:09
问题 I'm working on a joke web application. I work with C#, Entity Framework, MVC and I do code-first. Now when i try to read out something in my DB, the error I put in the title shows up. And I have no idea what to look for. I looked up Google but I didn't quite get an answer... I try to provide all the code that you could need to know: public class Context : DbContext { public DbSet<Categorie> Categories {get;set;} public Context() : base("Witze_DB") { } } public class HomeController :

Why did the new ASP.NET Identity tables stop using Guid (uniqueidentifier type) as keys?

我们两清 提交于 2019-12-23 09:01:07
问题 I'm trying to understand why the new ASP.NET Identity tables stopped using Guid (uniqueidentifier type) as keys - instead it is now using nvarchar(128) but still keep a Guid as a string ... Isn't it a huge waste? ( uniqueidentifier is just 2 integers vs the whole Guid as a 36 character string ) I'm suspecting that Entity Framework might be responsible for this... Is it safe to change back to uniqueidentifier keys? Can anyone tell me what are the benefits of using 36 character strings? 回答1:

Upgrade to EF 6.1.1 makes effect of [NotMapped] disappear

我的梦境 提交于 2019-12-23 07:57:18
问题 I have upgraded from EF 4.3.1 to 6.1.1 and now it seems like the annotation [NotMapped] is useless. Yes, i have change to correct assembly and everything looks fine on compilation. Everywhere where [NotMapped] is present the property is handled as a domain property and i get an error that EF can't find the matching column in database. Example: private bool _authenticated = true; [NotMapped] public bool Authenticated { get { return _authenticated; } set { _authenticated = value; } } Yes, it