entity-framework

C# Entity Framework: Linq Filter on GrandChildren and Conduct a Select on the Parent

て烟熏妆下的殇ゞ 提交于 2020-06-28 06:41:21
问题 Our company is currently using Entity Framework Net Core 2.2 with Sql Server Trying to find all Distinct customers who purchased a certain Product Input Parameter. When trying to do final select, it shows b lambda as Product. We need the Distinct Customers showing up last. How the EF Linq query be written to get this for distinct Customers? var taxAgencyDistinctList = db.Customer .SelectMany(b => b.Transactions) .SelectMany(b => b.Purchases) .Select(b => b.Product) .Where(b => b.BKProduct ==

How to insert graph in Entity Framework with circular dependency

北城以北 提交于 2020-06-28 06:09:11
问题 This is how database structure looks like: Vehicle has lot of CanNetworks and each CanNetwork has lot of ECUs . And that would save perfectly if that was only I have. But, each vehicle also has one special ECU called gatewayECU so problem happens with saving because entity framework core does not know how to handle that scenario. It needs to insert vehicle before inserting ecus, but how to insert vehicle when ecu is not inserted. This is what I tried: ignore (delete, invalidate) gatewayecu

Does EF core compares value to include columns in update statement?

烈酒焚心 提交于 2020-06-28 05:25:17
问题 I have the following code var dbContext = Setup.ConfigureDBContext(); var wo = await dbContext.WorkOrders.Where(x => x.WorkOrderID == 88).SingleOrDefaultAsync(); var t = wo.Confidence; wo.ModifiedDateTime = DateTime.UtcNow; wo.Confidence = t; await dbContext.SaveChangesAsync(); in the above query i am assigning the same Confidence but changing the ModifiedDateTime EF generates the following SQL exec sp_executesql N'SET NOCOUNT ON; UPDATE [WorkOrders] SET [ModifiedDateTime] = @p0 WHERE

Entity Framework Core - efficient way to update Entity that has children based on JSON representation of entity being passed in via Web API

天涯浪子 提交于 2020-06-28 03:43:22
问题 I am writing an .NET Core Web API which is backed by Entity Framework Core and having a PostgreSQL database underneath (AWS Aurora). I have been able to learn and successfully work with EF Core for inserts and querying data, which is great, but starting to look into UPDATES of existing entities and it's become unclear to me the most efficient way to achieve what I'm after. I have my Database Entities as a result of my Database First scaffolding exercise. I have an entity that is similar to

Unknown CS1003 Error

无人久伴 提交于 2020-06-27 18:38:27
问题 I can't compile my project for code-first migrations in entity framework past a certain point. I am reading in values from xml to populate a table. I have the following code: //EnrolmentProgramStartDate var programQuery = from r in context.EnrolmentPrograms select r; var programList = programQuery.ToList<Entities.MetaData.Enrolment.EnrolmentProgram>(); resourceName = "LearnLogicElicos_WebApi.SeedData.MetaData.Enrolment.enrolment_program_start_date.xml"; stream = assembly

Unknown CS1003 Error

醉酒当歌 提交于 2020-06-27 18:38:27
问题 I can't compile my project for code-first migrations in entity framework past a certain point. I am reading in values from xml to populate a table. I have the following code: //EnrolmentProgramStartDate var programQuery = from r in context.EnrolmentPrograms select r; var programList = programQuery.ToList<Entities.MetaData.Enrolment.EnrolmentProgram>(); resourceName = "LearnLogicElicos_WebApi.SeedData.MetaData.Enrolment.enrolment_program_start_date.xml"; stream = assembly

How use DbContext in migration?

别说谁变了你拦得住时间么 提交于 2020-06-27 18:30:27
问题 How can I use DbContext which works with the current database (that now use in migration). Example: namespace Data.SqlServer.Migrations { [DbContext(typeof(MyDbContext))] // I want use this context [Migration("CustomMigration_DataSeed")] public partial class DataSeedMigration : Migration { protected override void Up(MigrationBuilder migrationBuilder) { // add some entities _context.User.Add(new User()); } protected override void Down(MigrationBuilder migrationBuilder) { } } } Thanks for help!

Does the EF Fluent Api can setting the Minimum Length?

时光毁灭记忆、已成空白 提交于 2020-06-27 08:23:25
问题 It seems use the Fluent API has more flexibility. So I choose the way to follow always use the Fluent API to determine the feature it have in db instead use the annotations to. But here is the problem,I couldn't find the way to set the Minimum length. Is there a method to perform this? And i notice,there are no much topic discuss this way.Is the Fluent API way popular?? Hope we choose the right side. 回答1: This is impossible at the moment with EF. If you really have to set a minimum length,

Entity Framework Migration Azure DevOps Release Pipeline

女生的网名这么多〃 提交于 2020-06-27 08:11:23
问题 I'm trying to run migration on Azure DevOps Release Pipeline. Because I want to run my DB scripts automatically on every release. My release pipeline does not have source code, I just have compiled DLLs. When I execute this command on my local machine, it runs successfully. How can I convert this command so I can use it with DLLs. dotnet ef database update --project MyEntityFrameworkProject --context MyDbContext --startup-project MyStartupProject 回答1: If you don't want to include your source

EF Core lazy loading proxies return null randomly instead of entities

被刻印的时光 ゝ 提交于 2020-06-26 16:23:26
问题 I have a .Net Core 3.1 application with an SQL database. I use lazy-loading proxies to automatically retrieve data from related tables. Basically, I have a table, which references some other entities via 1-to-many or 1-to-1 relation. Thing is, most of the cases, every relation is OK, every entity is loaded and I can read it's properties (name field, for example). But, in very specific cases, those entities won't load , although relation Id is there. It looks like this: Model is like this: