entity-framework-core

EFCore returning too many columns for a simple LEFT OUTER join

限于喜欢 提交于 2019-11-30 18:32:37
I am currently using EFCore 1.1 (preview release) with SQL Server. I am doing what I thought was a simple OUTER JOIN between an Order and OrderItem table. var orders = from order in ctx.Order join orderItem in ctx.OrderItem on order.OrderId equals orderItem.OrderId into tmp from oi in tmp.DefaultIfEmpty() select new { order.OrderDt, Sku = (oi == null) ? null : oi.Sku, Qty = (oi == null) ? (int?) null : oi.Qty }; The actual data returned is correct (I know earlier versions had issues with OUTER JOINS not working at all). However the SQL is horrible and includes every column in Order and

Add constraint to existing SQLite table

孤街醉人 提交于 2019-11-30 18:24:27
I'm using SQLite, which doesn't support adding a constraint to an existing table. So I can't do something like this (just as an example): ALTER TABLE [Customer] ADD CONSTRAINT specify_either_phone_or_email CHECK (([Phone] IS NOT NULL) OR ([Email] IS NOT NULL)); Are there any workarounds for this scenario? I know: I can add a constraint for a new table, but it isn't new (and it's generated by my ORM, EF Core) I can do a "table rebuild" (rename table, create new one, copy old data, drop temp table) but that seems really complex Ideas Can I somehow make a copy of the table into a new table, with

Left Outer Join with Entity Framework Core

心已入冬 提交于 2019-11-30 17:40:43
问题 I'm trying to perform a left outer join request with EF7 (7.0.0-rc1-final), vNext RC1 (rc1-final) and SQL Server 2014 Database : Pet: Id, Name User: Id, Name, #PetId This one works: var queryWorks = from u in _context.Users join p in _context.Pets on u.PetId equals p.Id into pp from p in pp.DefaultIfEmpty() select new { UserName = u.Name, Pet = p }; but this one doesn't work (Message = "Sequence contains no elements"): var queryFails = from u in _context.Users join p in _context.Pets on u

No database providers are configured EF7

旧城冷巷雨未停 提交于 2019-11-30 17:38:33
I seem to be getting this error message when using Entity Framework 7 and MVC6 System.InvalidOperationException No database providers are configured. Configure a database provider by overriding OnConfiguring in your DbContext class or in the AddDbContext method when setting up services. I believe i have done everything i am supposed to be doing, so maybe its a bug. I am using version 7.0.0-beta7 of Entity Framework. I have setup my DbContext, an interface so i can mock DbContext (was needed in EntityFramework 6 for unit testing). My services take the interface as a constructor and i have setup

No service for type Identity.UserManager when using multiple identity users

孤街浪徒 提交于 2019-11-30 17:30:47
My setup Currently, I have two models that inherit from ApplicationUser , which inherits IdentityUser . The user classes are: public abstract class ApplicationUser : IdentityUser { [PersonalData] public string FirstName { get; set; } [PersonalData] public string LastName { get; set; } [NotMapped] public string FullName => $"{FirstName} {LastName}"; } public class StudentUser : ApplicationUser { [PersonalData] [Required] public string StudentNumber { get; set; } // A user belongs to one group public Group Group { get; set; } } public class EmployeeUser : ApplicationUser { } The ApplicationUser

EF Core - System.InvalidOperationException: ExecuteReader requires an open and available Connection. The connection's current state is closed

无人久伴 提交于 2019-11-30 17:18:40
问题 I'm running an ASP.NET Core 1.0 web app with Entity Framework Core. When the app has been running for a while (24 - 48 hours), the app starts crashing on every request to any endpoint or static resource throwing the error System.InvalidOperationException: ExecuteReader requires an open and available Connection. The connection's current state is closed. I can only recover from this by restarting the App Pool. I am configuring Entity Framework like this: Startup.cs public void ConfigureServices

ASP.NET Core and EF Core 1.1 - Diplay Data using Stored Procedure

北城以北 提交于 2019-11-30 16:55:54
I have problem with my query. I want to display the result on a view. [HttpGet] [ValidateAntiForgeryToken] public async Task<IActionResult> Index() { return View(await _Context.Employee .FromSql("EXEC sp_GetLoanDetails") .ToArrayAsync()); } Here is my list of items I want to view: public class StoredProcRow { [Key] public int empID { get; set; } public string empFullName { get; set; } public double EducationalLoan { get; set; } public double PettyCash { get; set; } public double BusinessLoan { get; set; } public double ApplianceLoan { get; set; } public double EmergencyLoan { get; set; }

UseSqlServer method missing MVC 6

我只是一个虾纸丫 提交于 2019-11-30 16:52:56
I am trying to implement Entity Framework 7 in MVC 6, and on this page here it says to do services.AddEntityFramework() .AddSqlServer() .AddDbContext<MusicStoreContext>(options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"])); But for me, the UseSqlServer method isnt visible? Anyone know how to make it visible? Or is this an old way of configuring entity framework? My startup.cs file looks like this using FluentValidation; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework

How can I use database Views in a scaffolded DbContext with Entity Framework Core 1.0 (EF7)

随声附和 提交于 2019-11-30 15:28:28
问题 Unfortunately Entity Framework Core 1.0 (formerly Entity Framework 7) does not yet support Views, and I'm trying to 'fake' it using a table. However the scaffolding dotnet dbcontext ef scaffold command doesn't currently recognize or generate views, and I want a single DbContext which allows querying a view and updating of tables. Is there a way to do this? This is the command I use to scaffold the DbContext: dotnet ef dbcontext scaffold -c MyStoreContext -o Model "Data Source=(local);Initial

Logging Generated SQL with EF Core 2 and Nlog

故事扮演 提交于 2019-11-30 14:38:12
I'm getting a little confused with how to log the generated SQL with asp.net core 2 and EntityFrameworkCore 2 and the correct way to go about it. After reading the this link from the MS docs it is saying that I should add during the services configuration in the startup.cs using .UseLoggerFactory(<LoggerFactory>) . However, this seems outdated as when I look to add the logger I get this message; Could someone please tell me the best way to add the logger to log the SQL for debug purposes? I also plan to use Nlog going forward for all my logging as opposed to the built in logging facilities, I