entity-framework-6

AddOrUpdate does not modify children

允我心安 提交于 2019-12-23 20:25:28
问题 I am using AddOrUpdate in my seed method to keep my permissions up to date, however, in the situation where the below code is updating the existing role (rather than creating it), any new Permissions I created are not being added to the role. What am I doing wrong? foreach (KeyValuePair<string, string[]> s in new Dictionary<string, string[]>{ {"Superuser", context.Permissions.Select<Permission, string>(p=>p.Name).ToArray()}, }) { Role r = new Role(); r.Name = s.Key; r.Permissions = new List

Using Test Doubles with DbEntityEntry and DbPropertyEntry

落花浮王杯 提交于 2019-12-23 19:23:16
问题 I am using the new Test Doubles in EF6 as outlined here from MSDN . VS2013 with Moq & nUnit. All was good until I had to do something like this: var myFoo = context.Foos.Find(id); and then: myFoo.Name = "Bar"; and then : context.Entry(myFoo).Property("Name").IsModified = true; At this point is where I get an error: Additional information: Member 'IsModified' cannot be called for property 'Name' because the entity of type 'Foo' does not exist in the context. To add an entity to the context

EF6 exception: DbExpressionBinding requires an input expression with a collection ResultType

那年仲夏 提交于 2019-12-23 16:49:15
问题 I'm facing an exception when I run this query (using LinqPad for debugging): int[] serviceCodes= new int[] { 1610, 1611, 1612 }; byte[] payModes = new byte[] { 1, 2 }; int[] months = new int[] { 10, 11, 12 }; int year = 2017; using (var context = new FinanceConnection()) { var result = from a in (from a in context.BILL_INFO_DETAILS where a.INPUT_STATUS == true && serviceCodes.Contains(a.SERVICE_INFO.SERVICE_CODE) && payModes.Contains(a.PAY_MODE_ID) && a.STAMP_DATE != null && months.Contains(a

Entity framework IQueryable extension methods do not work as a sub query

[亡魂溺海] 提交于 2019-12-23 16:37:08
问题 I like to write my queries using extension methods where possible. So the following is a query which works for me: int studentId = ( from u in db.Users .FromOrganisation(org.Id) .IsStudent() .IsActive() where u.ExtId == dto.StudentExtId select u.Id ).FirstOrDefault(); The extension methods are as follows: public static IQueryable<User> IsStudent(this IQueryable<User> u) { return u.Where(x => x.Type == (int)UserTypes.Student); } However, when I use extension methods in a sub-query I get the

EF: Should I explicitly close database connection when calling OpenConnection manually

守給你的承諾、 提交于 2019-12-23 15:14:10
问题 I open connection in constructor. Consider this code: public abstract class DataContext : DbContext, IDataContext { static DataContext() { if (DataContextConfiguration.UseSafePersian) { DbInterception.Add(new SafePersianInterceptor()); } } private readonly bool _saveChangesOnModify = false; protected DataContext(string nameOrConnectionString) : base(nameOrConnectionString) { this.OpenConnection(); } internal void OpenConnection() { if (((IObjectContextAdapter)this).ObjectContext.Connection

Could not load type 'System.Data.Entity.DbSetExtensions' from assembly 'EntityFramework

大兔子大兔子 提交于 2019-12-23 14:54:44
问题 Updated from entityframework 6.0.0-beta1 to 6.0.0-rc1 and when logging into my MVC5 application i get the following error {"Could not load type 'System.Data.Entity.DbSetExtensions' from assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.":"System.Data.Entity.DbSetExtensions"} [System.TypeLoadException]: {"Could not load type 'System.Data.Entity.DbSetExtensions' from assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken

How to ExecuteSqlCommand in Entity Framework without it being contained in a transaction

久未见 提交于 2019-12-23 14:38:48
问题 I need to execute a stored procedure with Entity Framework. Normally I call it like this: this.Context.Database.ExecuteSqlCommand("EXEC edi_UploadTransmission"); However, this particular stored procedure includes accessing a linked server. Since EF wraps ExecuteSqlCommand in a transaction, it is failing, as a linked server is not supported in a transaction (as far as I can tell). Is there a way to execute this stored procedure with Entity Framework without it being in a transaction? 回答1: Pass

How will I use breeze with Entity Framework 6 with .net 4.0

谁说胖子不能爱 提交于 2019-12-23 13:58:15
问题 I installed my 4.0 MVC project, Entity Framework 6 using nuget(to enable ode first migrations). Then I tried installing breeze package Breeze.Server.ContextProvider.EF6. But I'm having missing assembly reference errors for breeze. 回答1: The only way I was able to get Breeze working on .NET 4.0 with Entity Framework 6 was to create my own EF6ContextProvider using the Breeze source code from GitHub as a starting point. I created a project Breeze.WebApi.EF6 and added a class EF6ContextProvider.cs

EntityFramework database first - type mapping - map binary(8) from SQL to int in C#

∥☆過路亽.° 提交于 2019-12-23 13:30:24
问题 Inside SQL I have table that have primary key as binary(8). When I add that table to my model using Update Model from Database I can see that this column has type= Binary and in C# I get that column as byte[] . Can I map that column to int? I know I can create a view with CAST in SQL: SELECT Client_Id, CAST(Client_Id AS INT) AS NewClient_Id, * /*other columns*/ FROM dbo.Clients but this isn't a solution, because I must be able to write, not just read from that table. I know I can create

NHibernate Envers like Audit Log with Entity Framework 6+

匆匆过客 提交于 2019-12-23 13:06:10
问题 NHibernate Envers does a good job of creating an Audit Log whenever an entity is Updated/Deleted. Basically it creates an Audit table for each auditable entity and write a snapshot of the data into the Audit table. For e.g. if Customer records are saved in CUSTOMER table then audit log for Customer records will be saved in CUSTOMER_AUD table. In one of my projects we are using Entity Framework 6.1. I have searched and looked at various alternatives like AuditDBContext and EntityFramework