ef-code-first

Entity Framework Many to Many Cascade Delete Issue

非 Y 不嫁゛ 提交于 2019-12-11 04:23:35
问题 Having a strange issue working on a code first EF project. I have the following entities: public class Booking { public Guid BookingId { get; set; } public virtual List<AccountingDocumentItem> AccountingDocumentItems { get; set; } } public class AccountingDocumentItem { public Guid AccountingDocumentItemId { get; set; } public virtual List<Employee> Employees { get; set; } public virtual List<Booking> Bookings { get; set; } } public class Employee { public Guid EmployeeId { get; set; } public

.net core 2.1 EF Core reverse engineering errors VS 2017

可紊 提交于 2019-12-11 04:10:32
问题 Not having a great time with doing EF Core Reverse Engineering. Latest error The method or operation is not implemented. Scaffold-DbContext "The method or operation is not implemented" i get the same errors for both of these commands Running this from Package Manager Console within VS 2017: Scaffold-DbContext 'Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Chinook' Microsoft.EntityFrameworkCore.SqlServer and from command prompt: dotnet ef dbcontext scaffold "Data Source=(localdb)

SQL subquery result in LINQ and Entity Framework Code First

若如初见. 提交于 2019-12-11 04:03:45
问题 I want to make a query that'll return me entities and additionally a number of one of their associated entities. For example: select *, (select COUNT(*) from Forms where Contact_Id = Contacts.Id) as FormsCount from Contacts; My Contact entity has a property named FormsCount, but it isn't mapped since there's no column named like that in the table. Is it possible to write one LINQ query that'll return me Contact entities with the additional FormsCount property filled in? Alternatively, I'd be

Entity Framework DbContext Connection string in app.config/web.config not being seen

与世无争的帅哥 提交于 2019-12-11 03:56:12
问题 So, I have followed this instruction from ADO.NET team blog to try to make a small test project. I have double-checked everything. It doesn't seem to work and keeps saying connection string is missing. http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-model-amp-database-first-walkthrough.aspx Step. 1 Build this UserModels.dll. In the dll, App.Config file, edmx generated this connection string: (hit the 'test' button when making it, and it connects successfully, and generated the edmx

EF Fluent API many to one relation, navigation property is not fetched

*爱你&永不变心* 提交于 2019-12-11 03:48:55
问题 I have a database with the Entity Framework 5 RC (with Fluent API) working now, but I can't seem to get a specific relation to work. And it is driving me nuts for the past few nights I'm working on it. It is the following relation: Link to the database diagram As you can see, I have a Exercise which is related to an ExerciseType . The problem is, the Exercise.ExerciseType navigation property, is not loaded. The relation I made is as follows: EntityTypeConfiguration<Exercise> ... this

Issue loading child entity of a parent entity. Unidirectional mapping and 1 to 0..1 relationship with a Shared primary Key?

纵饮孤独 提交于 2019-12-11 03:23:22
问题 When I try to load child entity of parent entity it loads with default values. If i try to load explicitly it throws exception Multiplicity constraint violated . The role 'Association_Customer_Target' of the relationship 'CodeFirstNamespace.Association_Customer' has multiplicity 1 or 0..1. This exception is thrown while retrieving the child entities of a complex graph. I have a graph Association which has a child entity Customer with a relationship of one to zero or one and has an Independent

How to configure EF Code First to not map a specific type?

核能气质少年 提交于 2019-12-11 03:21:02
问题 I was getting the following error when runing such this code: var dbContext = new MyDbContext(); var list = dbContext.Set<TEntity>().ToList(); From the changes I made recently to codes I understood that because I added an event to the base class it causes all the problems: public PropertyChangedEventHandler PropertyChangedEvent { get; set; } Applying the NotMapped attribute to the above property my codes now are working again. Now I want to know if there is anyway to autmatically tell

Code First Migrations for dynamically assembled model

巧了我就是萌 提交于 2019-12-11 03:19:42
问题 My database model (sometimes referred to as " context ") is dynamically assembled at startup based on which services and/or plugins are installed. Plugins and services export their model definition fragments through my IoC container and the application core picks them up and runs them when the DbContext.OnModelCreating method is called. The question is: Can I (and how do I) use Code First Migrations with this setup ? (below is more information on what I've tried and what particular problems

Set DatabaseInitializerForType in config file for Custom Initializer to fire

99封情书 提交于 2019-12-11 03:17:22
问题 So I either get errors firing or nothing happens. I know that I have custom Entity Framework Initializer like this: using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Text; using System.Threading.Tasks; namespace EasyEntity { public class EasyInitializer : DropCreateDatabaseAlways<EasyContext> { protected override void Seed(EasyContext context) { List<Person> persons = new List<Person> { new Person { FirstName = "Waz", LastName = "Amattau

Entity Framework Code First navigational properties returning null fields

六眼飞鱼酱① 提交于 2019-12-11 03:15:17
问题 For a program I'm using EF code first for the first time. In the past I used linq to SQL en EF DbFirst. When retreiving the main record'I'm unable to load the subrecords using the navigational properties. I get an empty subrecord with all record-fields are 0 or null. When I want to apply eager loading. the .Include(x=>x.......) isn't showing my navigationals. I have set up the following classes: public Record() { Shipping = new ShippingData(); Delivery = new DeliveryData(); Items = new List