entity-framework-core

EF Core fix-up when querying subset of columns

假如想象 提交于 2019-12-11 17:52:08
问题 From the documentation: Entity Framework Core will automatically fix-up navigation properties to any other entities that were previously loaded into the context instance. So even if you don't explicitly include the data for a navigation property, the property may still be populated if some or all of the related entities were previously loaded. Entities setup: public class Page{ public Page () { Event = new HashSet<Event>(); } [Key] public int Id { get; set; } public string Title { get; set; }

Entity Framework Linq Query: How to Where on Multiple Nav Properties and Select from 3rd Nav Property

限于喜欢 提交于 2019-12-11 17:33:43
问题 I have the following models with nav propertiers set up in Entity Framework Core: CRMLocations (one-to-many) CRMPeoples CRMPeoples (one-to-many) CRMEmails CRMPeoples (one-to-many) CRMPhones I have the following working Query: var iqable = _crmDbContext.CRMPeoples .Where(p => p.Name.ToLower().Contains(query) || (from e in p.CRMEmails where e.EmailAddress.ToLower().Contains(query) select e).Any() || (from h in p.CRMPhones where h.PhoneNumberNormalized.Contains(query) select h).Any()) .Select(p

Entity Framework Core - How to handle Related Entity Mapping and Saving

天大地大妈咪最大 提交于 2019-12-11 17:24:18
问题 I have two related entity which is one-to-many relationship like below: class parent{ public string parentName{get;set;} public virtual ICollection<child> childs { get; set; } } class child{ public string childName{get;set;} public parent parent{get;set;} ["ForeignKey"] public int parentId {get; set;} } /// View Model class VMParent{ public string parentName{get;set;} /// a string array contains child name public string[] childlist { get; set; } } Suppose my parent currently contains 2 child

“The owned entity type requires to be referenced from another entity type via a navigation”

江枫思渺然 提交于 2019-12-11 17:11:54
问题 I have an entity in my application called Person. There are two types of users, Student and Professor, that inherit from Person. Every Person has a settings property: public abstract class Person { public Guid UserId { get; set; } public string Name { get; set; } public PersonSettings Settings { get; set; } } public class Student : Person { } public class Professor : Person { } My PersonSettings class is just a couple of properties. It isn't an entity to be stored in the database, so I marked

System.PlatformNotSupportedException: System.Data.SqlClient is not supported on this platform

断了今生、忘了曾经 提交于 2019-12-11 17:07:55
问题 I want to call a .netstandard2.0 library from a framework 4.7.2 library. I set up some test projects to check whether this would work. The test passes using a .Net Core 2.1 test project but fails with a framework 4.7.2 test project. The call stack is Test method UnitTestProject3.UnitTest1.TestMethod1 threw exception: System.PlatformNotSupportedException: System.Data.SqlClient is not supported on this platform. at System.Data.SqlClient.SqlConnection..ctor(String connectionString) at Microsoft

Entity Framework Core FromSql mock test cases

主宰稳场 提交于 2019-12-11 16:24:08
问题 I am using EF Core non-entity model with get stored procedure calling. See below sample code context.Query<ClassDTO>().FromSql("SpName @Param1, @Param2, @Param3", new SqlParameter[] { param1, param2, param3 }).ToList(); Code is working fine. But I need to write mock test cases. Can anyone help me out? How to mock Context.Query or how to write test cases for this code? I tried to implement the follow way: https://nodogmablog.bryanhogan.net/2017/11/unit-testing-entity-framework-core-stored

Using Service Fabric Actors with Entity Framework persistance

匆匆过客 提交于 2019-12-11 16:09:14
问题 I am just looking for a bit of advice about how to go about the title to this question. I currently have an asp.net core application which is backed by entity framework using DDD pattern that we are looking to migrate to a microservices architecture with service fabric. I am aware that actors can be persisted to disk and to memory, but does anyone have any experience with actors being persisted to an external storage such as MSSQL? The reason this comes about is that currently we run into

Multi-tenant authentication, IMustHaveTenant entity in ASP.NET Boilerplate Module Zero

假如想象 提交于 2019-12-11 16:04:19
问题 Multi-Tenant Authentication I have created a new tenant from the swagger UI as an admin and I can check in the data the tenant created successfully together with admin account . Now how do I login as the admin of the newly created tenant? Cos I tried Token-authenticating via Postman, specifying tenancyName in the request body and it only seems to authenticate the admin from default tenant - even when I put in rubbish in the tenancyName field, it won't detect any error or exception. I check

How to avoid not-safe context operations in EF Core? [duplicate]

泪湿孤枕 提交于 2019-12-11 15:55:04
问题 This question already has answers here : Entity Framework Core: A second operation started on this context before a previous operation completed (11 answers) Closed last year . I'd want to know how why creating instances of other classes with current database context instances as a parameter and using that db context causes this exception to be raised 'A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe.'

One-to-one relation + on-to-many relation using same entity

青春壹個敷衍的年華 提交于 2019-12-11 15:37:41
问题 I'm trying to create a customer entity that has multiple contact persons, as well as one primary contact person, but I can't seem to add the migration, as I'm getting the following error: Unable to determine the relationship represented by navigation property 'ContactPerson.Customer' of type 'Customer'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'. Customer public class