entity-framework

ASP.NET Web Api join two tables to make an array of objects

别说谁变了你拦得住时间么 提交于 2020-05-13 09:00:53
问题 This might be already asked question but I still can't solve my problem. I don't even know if I am on the right path. Some help will be appreciated. I have two model classes in an ASP.NET Web API project looking like this: namespace Artists.Models { public class Artist { public int ArtistID { get; set; } public string ArtistName { get; set; } } } and : namespace Artists.Models { public class Project { public int ProjectID { get; set; } public string ProjectName { get; set; } public int

ASP.NET Web Api join two tables to make an array of objects

折月煮酒 提交于 2020-05-13 08:59:15
问题 This might be already asked question but I still can't solve my problem. I don't even know if I am on the right path. Some help will be appreciated. I have two model classes in an ASP.NET Web API project looking like this: namespace Artists.Models { public class Artist { public int ArtistID { get; set; } public string ArtistName { get; set; } } } and : namespace Artists.Models { public class Project { public int ProjectID { get; set; } public string ProjectName { get; set; } public int

ASP.NET Web Api join two tables to make an array of objects

主宰稳场 提交于 2020-05-13 08:58:06
问题 This might be already asked question but I still can't solve my problem. I don't even know if I am on the right path. Some help will be appreciated. I have two model classes in an ASP.NET Web API project looking like this: namespace Artists.Models { public class Artist { public int ArtistID { get; set; } public string ArtistName { get; set; } } } and : namespace Artists.Models { public class Project { public int ProjectID { get; set; } public string ProjectName { get; set; } public int

How do I mock DbContext using NSubstitute and then add/remove data

↘锁芯ラ 提交于 2020-05-12 15:42:20
问题 I need to mock EF's DbContext . I use the approach here and it works well. // mock a DbSet var mockDbSet = Substitute.For<DbSet<Foo>, IQueryable<Foo>>(); var data = new List<Foo>().AsQueryable(); ((IQueryable<Foo>)mockDbSet).Provider.Returns(data.Provider); ((IQueryable<Foo>)mockDbSet).Expression.Returns(data.Expression); ((IQueryable<Foo>)mockDbSet).ElementType.Returns(data.ElementType); ((IQueryable<Foo>)mockDbSet).GetEnumerator().Returns(data.GetEnumerator()); // now add it to a mock

ToArrayAsync() throws “The source IQueryable doesn't implement IAsyncEnumerable”

只愿长相守 提交于 2020-05-12 12:12:18
问题 I have a MVC project on ASP.NET Core, my problem is connected with IQueryable and asynchronous. I wrote the following method for search in IQueryable<T> : private IQueryable<InternalOrderInfo> WhereSearchTokens(IQueryable<InternalOrderInfo> query, SearchToken[] searchTokens) { if (searchTokens.Length == 0) { return query; } var results = new List<InternalOrderInfo>(); foreach (var searchToken in searchTokens) { //search logic, intermediate results are being added to `results` using `AddRange(

ToArrayAsync() throws “The source IQueryable doesn't implement IAsyncEnumerable”

不打扰是莪最后的温柔 提交于 2020-05-12 12:11:43
问题 I have a MVC project on ASP.NET Core, my problem is connected with IQueryable and asynchronous. I wrote the following method for search in IQueryable<T> : private IQueryable<InternalOrderInfo> WhereSearchTokens(IQueryable<InternalOrderInfo> query, SearchToken[] searchTokens) { if (searchTokens.Length == 0) { return query; } var results = new List<InternalOrderInfo>(); foreach (var searchToken in searchTokens) { //search logic, intermediate results are being added to `results` using `AddRange(

ToArrayAsync() throws “The source IQueryable doesn't implement IAsyncEnumerable”

十年热恋 提交于 2020-05-12 12:09:32
问题 I have a MVC project on ASP.NET Core, my problem is connected with IQueryable and asynchronous. I wrote the following method for search in IQueryable<T> : private IQueryable<InternalOrderInfo> WhereSearchTokens(IQueryable<InternalOrderInfo> query, SearchToken[] searchTokens) { if (searchTokens.Length == 0) { return query; } var results = new List<InternalOrderInfo>(); foreach (var searchToken in searchTokens) { //search logic, intermediate results are being added to `results` using `AddRange(

Difference between Where().Count() and Count()

…衆ロ難τιáo~ 提交于 2020-05-11 05:24:12
问题 using (DBEntities db = new DBEntities()) { var employeeAgedAbove30 = db.Employees.Where(s => s.Age > 30).Count(); // Method 1 employeeAgedAbove30 = db.Employees.Count(s => s.Age > 30); // Method 2 } Consider the above example where I take a list of employees aged above 30. What is the difference between Method 1 and Method 2? Which one would you prefer and why? 回答1: I would prefer the second method for the readability. If you look at the generated sql code it is the same. Method 1: db

Select records that does not exist in another table in Entity Framework

丶灬走出姿态 提交于 2020-05-10 07:02:53
问题 I have two tables - "Customer" table and "Blacklist" customer table. When I blacklist a customer, I put the customerid as a foreign key to Blacklist table. What I want is to get CusId and Name that are not in the BlackList Table. How can I code this Entity Framework C#? Customer --------- (CusId,Name,Telephone,Email) Blacklist --------- (CusId) 回答1: What you want is something like the following: db.Customers .Where(c => !db.Blacklists .Select(b => b.CusId) .Contains(c.CusId) ); EF will

Select records that does not exist in another table in Entity Framework

隐身守侯 提交于 2020-05-10 07:01:29
问题 I have two tables - "Customer" table and "Blacklist" customer table. When I blacklist a customer, I put the customerid as a foreign key to Blacklist table. What I want is to get CusId and Name that are not in the BlackList Table. How can I code this Entity Framework C#? Customer --------- (CusId,Name,Telephone,Email) Blacklist --------- (CusId) 回答1: What you want is something like the following: db.Customers .Where(c => !db.Blacklists .Select(b => b.CusId) .Contains(c.CusId) ); EF will