ef-core-3.0

Sum of hours (HH:MM) in Linq

点点圈 提交于 2020-02-24 06:12:31
问题 I am having "TimeClocked" in my database table in the format HH.mm and I want to sum all the "TimeClocked" using LINQ. I have tried this aggregate function. var data = _projectDbContext .Tasks .Where(x => x.Project.CompanyId == companyId && x.Status == true) .Select(e => TimeSpan.Parse(e.TimeClocked)) .Aggregate(TimeSpan.FromMinutes(0), (total, next) => total + next) .ToString(); I am using EF Core 3.0.0 . It's showing error like this. Processing of the LINQ expression 'Aggregate<TimeSpan,

How to use stored procedures with SqlParameters in EF Core 3.0

ⅰ亾dé卋堺 提交于 2020-01-11 09:49:30
问题 I have tried the below var p = new SqlParameter("Option", "AUTHENTICATE"); var user = _context.Set<User>().FromSqlRaw("EXECUTE dbo.spGeneral_Authenticate @Option", p).ToList(); var user = _context.Set<User>().FromSqlRaw("EXECUTE dbo.spGeneral_Authenticate @Option=@Option", p).ToList(); and SqlParameter[] ps = new SqlParameter[1]; ps[0] = new SqlParameter("Option", "AUTHENTICATE"); var user = _context.Set<User>().FromSqlRaw("EXECUTE dbo.spGeneral_Authenticate @Option", ps).ToList(); var user =

Upgraded to EF Core 3.1 and now IProperty.get_ClrType is missing

本秂侑毒 提交于 2020-01-06 05:38:06
问题 When I upgraded my project from EF Core 2.2 to EF Core 3.1 I started getting this error: Method not found: 'System.Type Microsoft.EntityFrameworkCore.Metadata.IProperty.get_ClrType()'. This is in a Breeze module. I looked in the Breaking Changes and could not see anything that matches this (though it could be that the metadata references are including this and I just don't understand them). Is this supposed to be missing? Is there a workaround? 来源: https://stackoverflow.com/questions/59205665

.Net Core 3 and EF Core 3 Include Problem (JsonException)

 ̄綄美尐妖づ 提交于 2019-12-22 19:23:49
问题 I'm trying to develop an application using .NET Core 3 and EF Core. I encountered an error that I could not find a solution for. I could not do on ".Net Core 3" a structure which can be simply created with PHP eloquent. Model; public NDEntityContext(DbContextOptions<NDEntityContext> options) : base(options) { } public DbSet<User> Users { get; set; } public DbSet<Order> Orders { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<User>(entity =>

EF Core 3.0 SumAsync triggers aggregate function exception

杀马特。学长 韩版系。学妹 提交于 2019-12-20 02:30:36
问题 I am in the process of upgrading to EF Core 3.0 and .NET Core 3.0, but some of my queries stopped working. Here is an example: I have a table called Bins , I have another table which is called BinItems , now it has, of course, a one to many relationship. BinItems has a property called Qty , and I want to sum up all the Qty from BinItems based on criteria given by the client in a filter. So here is the code: var query = _binRepository.Table; if (filter.LastRecountDate != null) { query = query

EF Core 3.0 adding connected entity to collection fails in One To Many relationship

假装没事ソ 提交于 2019-12-14 03:00:51
问题 I try to add entity through the navigation property of collection, but the following message comes up: "Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions." The models are: SuggestionGroupDb: public class SuggestionGroupDb { public Guid Id { get; set; } [Required] public

Stored Procedures in EF Core 3.0

情到浓时终转凉″ 提交于 2019-12-13 01:18:59
问题 How to use stored procedures in EF Core 3.0 ? I have tried the following var user = await _context.Query<User>().FromSql("EXECUTE dbo.spGeneral_Authenticate").FirstOrDefaultAsync(); var user = await _context.Query<User>().FromSqlRaw("EXECUTE dbo.spGeneral_Authenticate").FirstOrDefaultAsync(); var user = await _context.Set<User>().FromSql("EXECUTE dbo.spGeneral_Authenticate").FirstOrDefaultAsync(); var user = await _context.Set<User>().FromSqlRaw("EXECUTE dbo.spGeneral_Authenticate")

Suppress EF core 3.0.x initialized msg

给你一囗甜甜゛ 提交于 2019-12-11 12:25:18
问题 I have: protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { string connectionString = "mydb.db;"; optionsBuilder .UseLoggerFactory(MainWorker.ConsoleLoggerFactory) .EnableSensitiveDataLogging(true) .UseSqlite(connectionString); } Whenever I access my DBContext the console shows info: Microsoft.EntityFrameworkCore.Infrastructure[10403] Entity Framework Core 3.0.0-preview4.19176.6 initialized Is there a way to filter out this particular message ? as I do a lot of

EF Core 2.2 LINQ query not working in EF Core 3.0

。_饼干妹妹 提交于 2019-11-27 06:51:16
问题 Below code works fine at EF Core 2.2 bu not working on EF core 3.0 var items = (from asset in Context.Assets join assetCategory in Context.AssetCategories on asset.CategoryId equals assetCategory.Id group assetCategory by assetCategory.Id into assetCategories select new AssetCategorySummary { CategoryId = assetCategories.Key, CategoryName = assetCategories.Select(p => p.CategoryName).FirstOrDefault(), TotalAsset = assetCategories.Count() }).ToListAsync(); the error I am getting: Processing of