How to remove child one to many related records in EF code first database?
In EF6 a faster way to do the operation is… context.Children.RemoveRange(parent.Children)
In EF6 a faster way to do the operation is… context.Children.RemoveRange(parent.Children)
The types and the names of the properties in the anonymous types must match: new { p1 = q.QOT_SEC_ID, p2 = dpr.DPR_TS } equals new { p1 = (decimal)p.PAY_SEC_ID, p2 = p.PAY_DATE } or if p.PAY_SEC_ID were an int?: new { p1 = (int?)q.QOT_SEC_ID, p2 = dpr.DPR_TS } equals new { p1 = p.PAY_SEC_ID, p2 … Read more
Are you looking at the designer or code view? You can force the designer to open by right clicking on your EDMX file and selecting Open With -> ADO.NET Entity Data Model Designer Right click on the designer surface of the EDMX designer and click Update Model From Database… All entities are refreshed by default, … Read more
Use just the Include extension on IQueryable. It is available in EF 4.1 assembly. If you don’t want to reference that assembly in your upper layers create wrapper extension method in your data access assembly. Here you have example: public static IQueryable<T> IncludeMultiple<T>(this IQueryable<T> query, params Expression<Func<T, object>>[] includes) where T : class { if … Read more
First() is causing this if your select returns 0 rows. You either have to catch that exception, or use FirstOrDefault() which will return null in case of no elements.
On EF core .. Composite keys can only be configured using the Fluent API – conventions will never setup a composite key and you can not use Data Annotations to configure one. Here is the Fluent API version : Note: This is just an example. Please adjust it according to your use case. // (In … Read more
Don’t use classes with the same unqualified name – EF uses only class names to identify the type mapped in EDMX (namespaces are ignored) – it is a convention to allow mapping classes from different namespaces to single model. The solution for your problem is to name your classes in BLL differently.
As already indicated by Ladislav in the comment, you need to disable automatic change detection to improve performance: context.Configuration.AutoDetectChangesEnabled = false; This change detection is enabled by default in the DbContext API. The reason why DbContext behaves so different from the ObjectContext API is that many more functions of the DbContext API will call DetectChanges … Read more
Is this because the Question has Answers and the Answers have a reference back to Question? Yes. It cannot be serialized. EDIT: See Tallmaris’s answer and OttO’s comment as it is simpler and can be set globally. GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; Old Answer: Project the EF object Question to your own intermediate or DataTransferObject. This Dto … Read more
Entity Framework Core 1.0 You should just need to update the tools section of your project.json file to include this: “Microsoft.EntityFrameworkCore.Tools”: { “version”: “1.0.0-preview1-final”, “imports”: [ “portable-net45+win8+dnxcore50”, “portable-net45+win8” ] } This should make the dotnet ef commands available. Important I should also note here that the dotnet ef commands will only be available when running … Read more