entity-framework

LINQ is Generating Extra IS NULL Condition in SQL Statement

巧了我就是萌 提交于 2020-05-10 04:12:59
问题 I'm writing some LINQ to fetch records based on an email, however, the generated SQL contains an additional IS NULL condition which doesn't need to be there because I am checking the parameter value for null in the code prior to adding the condition to the query. My LINQ code is: if (email != null) { query = query.Where(r => r.Email == email); } The SQL condition generated from this is: (([Extent1].[Email] = @p__linq__0) OR (([Extent1].[Email] IS NULL) AND (@p__linq__0 IS NULL))) The ((

LINQ is Generating Extra IS NULL Condition in SQL Statement

本秂侑毒 提交于 2020-05-10 04:12:30
问题 I'm writing some LINQ to fetch records based on an email, however, the generated SQL contains an additional IS NULL condition which doesn't need to be there because I am checking the parameter value for null in the code prior to adding the condition to the query. My LINQ code is: if (email != null) { query = query.Where(r => r.Email == email); } The SQL condition generated from this is: (([Extent1].[Email] = @p__linq__0) OR (([Extent1].[Email] IS NULL) AND (@p__linq__0 IS NULL))) The ((

LINQ is Generating Extra IS NULL Condition in SQL Statement

本小妞迷上赌 提交于 2020-05-10 04:11:24
问题 I'm writing some LINQ to fetch records based on an email, however, the generated SQL contains an additional IS NULL condition which doesn't need to be there because I am checking the parameter value for null in the code prior to adding the condition to the query. My LINQ code is: if (email != null) { query = query.Where(r => r.Email == email); } The SQL condition generated from this is: (([Extent1].[Email] = @p__linq__0) OR (([Extent1].[Email] IS NULL) AND (@p__linq__0 IS NULL))) The ((

MVC design pattern, service layer purpose?

我的未来我决定 提交于 2020-05-09 18:05:29
问题 Let's say I have a following repo pattern : interface IGenericRepo<T> where T : class { IEnumerable<T> GetAll(); T GetById(object id); void Insert(T obj); void Update(T obj); void Delete(T obj); void Save(); } interface ICustRepo : IGenericRepo<Cust> { IEnumerable<Cust> GetBadCust(); IEnumerable<Cust> GetGoodCust(); } public class CustRepo : ICustRepo<Cust> { //implement method here } then in my controller : public class CustController { private ICustRepo _custRepo; public CustController

The entity type 'Microsoft.AspNetCore.Mvc.Rendering.SelectListGroup' requires a primary key to be defined [duplicate]

情到浓时终转凉″ 提交于 2020-05-09 06:03:07
问题 This question already has answers here : The entity type 'Uri' requires a primary key to be defined (2 answers) Closed 13 days ago . New to .Net Core. Trying to implement a dropdown list similar to: MVC6 Dropdownlist of Countries In my model class I have public SelectList SiteList { get; set; } In my controller, I have: var sites = _context.Site.OrderBy(s => s.Name).Select(x => new { Id = x.ID, Value = x.Name }); var model = new Issue(); model.SiteList = new SelectList(sites, "Id", "Value");

Start a Task in the Form Shown event

孤者浪人 提交于 2020-05-09 05:56:02
问题 I want to bind a ComboBox to an EF Core entity of 53k rows. This takes some time, around 10 seconds. I thought that if I put the binding process in the Form Shown event, the UI will stay responsive. But this was not the case. What I've tried: Private Sub frmCerere_Shown(sender As Object, e As EventArgs) Handles Me.Shown Task.Factory.StartNew(Sub() GetProducts(cmbProduse), TaskCreationOptions.LongRunning) End Sub Public Shared Sub GetProducts(ctrl As ComboBox) Using context As EnsightContext =

How to handle concurrent DbContext access in dataloaders / GraphQL nested queries?

孤者浪人 提交于 2020-05-09 05:41:52
问题 I'm using a couple of dataloaders that use injected query services (which in turn have dependencies on a DbContext). It looks something like this: Field<ListGraphType<UserType>>( "Users", resolve: context => { var loader = accessor.Context.GetOrAddBatchLoader<Guid, IEnumerable<User>>( "MyUserLoader", userQueryService.MyUserFunc); return loader.LoadAsync(context.Source.UserId); }); Field<ListGraphType<GroupType>>( "Groups", resolve: context => { var loader = accessor.Context

How to select top N rows for each group in a Entity Framework GroupBy with EF 3.1

拟墨画扇 提交于 2020-05-09 05:37:08
问题 I need to get top 10 rows for each group in a table with entity framework. Based on other solution on SO, I tried 2 things: var sendDocuments = await context.Set<DbDocument> .Where(t => partnerIds.Contains(t.SenderId)) .GroupBy(t => t.SenderId) .Select(t => new { t.Key, Documents = t.OrderByDescending(t2 => t2.InsertedDateTime).Take(10) }) .ToArrayAsync(); error: System.InvalidOperationException: 'The LINQ expression '(GroupByShaperExpression: KeySelector: (d.SenderId), ElementSelector:

“Object reference not set to an instance of an object” when creating a new Web API controller with EF Scaffolding in Visual Studio 2012

旧时模样 提交于 2020-05-09 05:07:09
问题 I have an MVC4/Web API project, with an Entity Framework, Code First data model. When I try to create a new API Controller with read/write methods using a data context & model, I get an alert saying "Object reference not set to an instance of an object". I've done a bit of searching and found that some causes are incorrect project type Guids in the .csproj file, incomplete installation of the MvcScaffolding nuget package and one suggestion of installing Powershell 3. I have made sure all my

What's the right way to suppress EF warnings?

喜夏-厌秋 提交于 2020-05-08 06:36:31
问题 I would like to suppress these warnings but I could not figure out how to do it. 回答1: Those are not warnings you are seeing, those are Errors. The output tells you very clearly when a diagnostic message is a warning or an error. You've given the compiler an error number (6002) and told it to suppress the warning with that number, but such a warning does not exist. So, you've only succeeded in creating an additional error In this case, the message you're trying to suppress is a fatal compiler