entity-framework-core

How to get Inner Join using navigation property in Entity Framework Core

£可爱£侵袭症+ 提交于 2020-12-06 16:25:55
问题 I want to generate a query that uses an inner join for a one to one relationship using a navigation property. This is for an existing database that I cannot change. Here are what my entities look like: [Table("Info")] public class Info { [Key] public int InfoId { get; set; } public string Name { get; set; } public virtual MoreInfo MoreInfo { get; set; } } [Table("MoreInfo")] public class MoreInfo { [Key] public int InfoId { get; set; } public string OtherName { get; set; } public int

Entity Framework Core postgresql Array Type Mapping not working

夙愿已清 提交于 2020-12-06 12:37:48
问题 I have a strange problem, maybe it is something that I'm missing out, but I have the following LINQ Lambda query: var ss = ctx.ShipZones.SelectMany( z => ctx.ShipDecks, (z, d) => new { Zone = z.ZIndex, Deck = d.DIndex, Value = ctx.Tags .AsExpandable() .Include(s => s.TagSettings.Device.System) .Where(s => s.TagSettings.TagTypeId == 171 && s.TagSettings.Device.System.Id == z.Id && s.TagSettings.Device.ControlArea.Contains(d.Id) ) .Average(s => s.Value) } ).ToList(); According to this article,

EF Core, LINQ Operator '=' in VB.NET

拜拜、爱过 提交于 2020-12-06 06:02:39
问题 I have the next Code in EF Core 3.1 in language VB.NET Dim supplierID as string="1545464" Dim results = (From pa In DC.product.AsNoTracking() Where pa.supplierID = supplierID Select pa) The exception throw is: The LINQ expression 'DbSet<product> .Where(p => Operators.CompareString( Left: p.supplierID, Right: __$VB$Local_supplierID_0, TextCompare: False) == 0)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by

Are EF Core 3.1 ExecuteSqlRaw / ExecuteSqlRawAsync drop-in replacements for ExecuteSqlCommand / ExecuteSqlCommandAsync?

不打扰是莪最后的温柔 提交于 2020-12-04 18:28:45
问题 Upon upgrade to EFCore 3.1 deprecated warnings appeared: Warning CS0618 'RelationalDatabaseFacadeExtensions.ExecuteSqlCommandAsync(DatabaseFacade, RawSqlString, params object[])' is obsolete: 'For the async execution of SQL queries using plain strings, use ExecuteSqlRawAsync instead. For the async execution of SQL queries using interpolated string syntax to create parameters, use ExecuteSqlInterpolatedAsync instead.' Warning CS0618 'RelationalDatabaseFacadeExtensions.ExecuteSqlCommand

Unable to consolidate NuGet package transitive dependency versions in two NET Standard projects

一曲冷凌霜 提交于 2020-12-03 07:50:30
问题 Adding EF Core to a NET Standard project introduces transitive dependency versions incompatible with NuGet packages in other projects I have a solution with multiple .NET Standard 2.0 projects. One Project A uses the Google.Protobuf (3.11.2) NuGet package, that depends on System.Memory (4.5.3) System.Buffers (4.4.0) System.Numerics.Vectors (4.4.0) System.Runtime.CompilerServices.Unsafe (4.5.2) A few other projects also depend on System.Memory and all use the same dependency versions . Another

Unable to consolidate NuGet package transitive dependency versions in two NET Standard projects

血红的双手。 提交于 2020-12-03 07:49:42
问题 Adding EF Core to a NET Standard project introduces transitive dependency versions incompatible with NuGet packages in other projects I have a solution with multiple .NET Standard 2.0 projects. One Project A uses the Google.Protobuf (3.11.2) NuGet package, that depends on System.Memory (4.5.3) System.Buffers (4.4.0) System.Numerics.Vectors (4.4.0) System.Runtime.CompilerServices.Unsafe (4.5.2) A few other projects also depend on System.Memory and all use the same dependency versions . Another

EF Core 3.0 translating string.Equals ordinalIgnoreCase correctly

邮差的信 提交于 2020-12-01 11:07:40
问题 Before EF Core 3.0 this worked fine (evaluated on server+client): var exists = await _context.Countries.AsNoTracking().AnyAsync(x => x.CountryCode.Equals(country.CountryCode, StringComparison.OrdinalIgnoreCase)); What is the best/preferred method to translate the string.Equals(str, StringComparison.OrdinalIgnoreCase) -part now in EF Core 3.0, so that the query evaluates only on the server side. var exists = await _context.Countries.AsNoTracking().AnyAsync(x => x.CountryCode.ToUpper() ==

Your startup project doesn't reference Microsoft.EntityFrameworkCore.Design

♀尐吖头ヾ 提交于 2020-11-30 06:10:10
问题 I have 2 projects in my solution, I have a project with Entity Framework Core installed: And in the other ASP.NET Web API project I have these packages: <?xml version="1.0" encoding="utf-8"?> <packages> <package id="Antlr" version="3.5.0.2" targetFramework="net461" /> <package id="Microsoft.ApplicationInsights" version="2.5.1" targetFramework="net461" /> <package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.4.0" targetFramework="net461" /> <package id="Microsoft

Load child entity on the fetch of the Parent entity EFCore

筅森魡賤 提交于 2020-11-29 09:39:11
问题 I have the below model. What is the better way to load the parent entity with child entity at the time of fetching from the DB with find method? Parent Entity: public class Client { public int Id { get; set; } public string LastName { get; set; } public string Gender { get; set; } public DateTime DateOfBirth { get; set; } public Address Address { get; set; } } Child Entity: public class Address { public int Id { get; set; } public string FirstLine { get; set; } public string SecondLine { get;

Audit trail with Entity Framework Core

痴心易碎 提交于 2020-11-24 19:59:08
问题 I have an ASP.NET core 2.0 using Entity Framework core on a SQL Server db. I have to trace and audit all the stuff made by the users on the data. My goal is to have an automatic mechanism writing all what is happening. For example, if I have the table Animals, I want a parallele table "Audit_animals" where you can find all the info about the data, the operation type (add, delete, edit) and the user who made this. I already made this time ago in Django + MySQL, but now the environment is