entity-framework-6

Why is compiler requesting reference to Entity Framework in User Interface project?

南笙酒味 提交于 2019-12-12 16:41:36
问题 I am trying to learn how to create a Winform C# app, that uses EF with repository pattern. From my understanding, UI layer should be independent from Entity Framework (it uses data through repository and it shouldn't care if there is an Entity framework or any other data provider), but compiler is showing and error if WinForms project is not having reference to Entity framework (when I add reference to EF, everything works fine) Error message No Entity Framework provider found for the ADO.NET

No context type was found in the assembly EF6

大兔子大兔子 提交于 2019-12-12 16:36:42
问题 I'm working on a nopCommerce based project. In order to update custom entity I want to enable EF migrations. So I run following command: Enable-Migrations -StartUpProjectName nop.web -ContextProjectName Nop.Plugin.Payments.Deposit -verbose and get the error: Using StartUp project 'Nop.Web'. System.Data.Entity.Migrations.Infrastructure.MigrationsException: No context type was found in the assembly 'Nop.Plugin.Payments.Deposit'. at System.Data.Entity.Utilities.TypeFinder.FindType(Type baseType,

Replicate Entire Row In Entity Framework Core

断了今生、忘了曾经 提交于 2019-12-12 16:06:50
问题 I am trying to retrieve a row from database , changing certain columns value in it and adding it as new row (Entity Framework Core), But it is giving me error Cannot insert explicit value for identity column in table 'Audit_Schedules' when IDENTITY_INSERT is set to OFF. This table have a Primary Key "ScheduleId" Below is my Code AuditSchedules _schedules = new AuditSchedules(); using (var ctx = new QuestionnaireEntities(_configuration)) { _schedules = ctx.AuditSchedules.Where(x => x

How to map inherited entities in EF code-first

那年仲夏 提交于 2019-12-12 15:38:09
问题 I'm trying to map the AdventureWorks 2012 sample database to an EF 6.1.3 code-first data layer, and am stuck at how to map the Employee and Person entities. Employee should apparently derive from Person , with a Person.PersonType of EM , but I don't know how to map this using EntityTypeConfiguration<TEntity> 'mapping' classes. Knowing this, I could also map Person to derive from BusinessEntity . 回答1: I will explain how to perform the mapping between the Employee and the Person tables using

Database first approach with automatic CRUD logging

旧城冷巷雨未停 提交于 2019-12-12 15:33:11
问题 I have setup EF+ Audit as follows: public partial class FocusConnection : DbContext { static FocusConnection() { AuditManager.DefaultConfiguration.AutoSavePreAction = (context, audit) => // ADD "Where(x => x.AuditEntryID == 0)" to allow multiple SaveChanges with same Audit (context as FocusConnection).AuditEntries.AddRange(audit.Entries); } public override int SaveChanges() { var audit = new Audit(); audit.PreSaveChanges(this); var rowAffecteds = base.SaveChanges(); audit.PostSaveChanges();

MySQL Unknown column 'Extent1.ID' in 'on clause' with EF6

柔情痞子 提交于 2019-12-12 15:10:12
问题 I have the following class structure public class Question { public long ID { get; set; } public string Content { get; set; } public DateTime On { get; set; } public Member Member { get; set; } public List<Answer> Answers { get; set; } } public class Answer { public long ID { get; set; } public string Content { get; set; } public DateTime On { get; set; } public Member Member { get; set; } public List<Star> Stars { get; set; } public List<Reply> Replys { get; set; } } public class Reply {

EF6 stored procedure with no results

南楼画角 提交于 2019-12-12 13:53:11
问题 My environment is VS 2012, C#, EF6 and SQL Server 2008 R2. I want to execute a stored procedure to delete records with no return value using the pattern: dataContext.Database.SqlQuery<return type>("name", parameter) If there are no results returned e.g. with NO COUNT ON what should I set as the return type? Seems that it should be simple but I cannot find an answer anywhere. I tried dataContext.Database.SqlQuery("name", parameter) but that returns a compile error: The best overloaded method

How to create nested transactions in Entity Framework using TransactionScope?

强颜欢笑 提交于 2019-12-12 13:08:33
问题 I know EF 6 DbContextTransaction, but I'm getting bad experience with it over nested transaction. Now I'm trying solely using TransactionScope for nested transaction, but also having problem. This code involved 3 tables changes. When an exception occured in inner trx dbTrx2, it messed up dbTrx1, as dataChg3.SaveChanges() will failed. using (var dbTrx1 = new System.Transactions.TransactionScope()) { ... dataChg1..... foreach(var dataChg2 in listOfDataChg2) { ... try { using (var dbTrx2 = new

LocalDB and Entity Framework 6 - Security

旧时模样 提交于 2019-12-12 12:24:21
问题 I am trying to figure out a way to use a LocalDB in place of SQL for integration testing of EF6 queries (this would allow us to run integration tests on our build server). It seems like I should be able to replicate my database in SQL Express, detach, and import into my test project. I would expect from there I can modify my connection string in my test project to hit the local database file. I am running into a security issue though. I need to get SQL security working to pass in a user id

DbFunction “cannot be translated into a LINQ to Entities store expression”

北城以北 提交于 2019-12-12 12:05:42
问题 I'm trying to access database funciton using linq to sql. Herer is my SQL Scalar Function: CREATE FUNCTION Echo(@text NVARCHAR(MAX)) RETURNS NVARCHAR(MAX) AS BEGIN RETURN @text; END; I created a class called EntityFunction to call Functions in Sql Server: public static class EntityFunctions { [DbFunction("SqlServer", "Echo")] public static string Echo(string parameter) { throw new NotImplementedException(); } } And here is my DbContext: public class MainDbContext : DbContext { #region