linq

How to use Linq to group, sum or retrieve total. My current code returns nothing

大城市里の小女人 提交于 2020-07-22 12:49:10
问题 I have this code which I'm trying to use in retrieving the fish pond with the highest use of feed in a month, so I need to group by Pool_Name , sum feed usage and then select the highest record after sorting. Here's an example code: var hfeed = db.feed_fish .Where(x => (DbFunctions.TruncateTime(x.Feed_Time) >= frm && DbFunctions.TruncateTime(x.Feed_Time) <= todat)) .GroupBy(x => x.Pond_Name) .Select(y => new feed_fish { Pond_Name = y.Key, Total_feed_weight = y.Sum(d => d.Total_feed_weight) })

How to Join In LiteDb

不羁的心 提交于 2020-07-22 09:33:24
问题 How can i join between two table in LiteDb Like SQL Example : I Have Two table User and ActivityLog Here is the Model public class ActivityLog { [BsonId] public int Id { get; set; } public string UserId { get; set; } public string Action { get; set; } public DateTime ActionDateTime { get; set; } } public class User { [BsonId] public int Id { get; set; } public string UserId { get; set; } public string UserName { get; set; } public DateTime LoginDate { get; set; } } I need to join Activity

MS Graph - LINQ query returning incorrect results

梦想的初衷 提交于 2020-07-22 05:51:08
问题 Question : Following is returning one incorrect value. What I may be missing and how can it be corrected? The issue seems to be purely related to use of LINQ and not MS Graph. Remark : Although this is a simpler case with only two types of values (Azure AD and MS Account), in real scenarios there will be more than just two cases. Hence, we can't just use a simple ternary operator (e.g. condition ? consequent : alternative ) for a simple case - instead, it has to be embedded with multiple

using .Contains() with linq-to-sql

点点圈 提交于 2020-07-19 04:28:13
问题 I have the following query that receives a list of ints as a parameter: public int GetMostRecent(List<int> TheIDs) { ...using MyDC... var TheMostRecentID = (from d in MyDC.Data where TheIDs.Contains(d.ID) orderby d.DateTime select d.ID).LastOrDefault(); } Is this the best way to match a list within a parameter collection to data in the database or is there a better way than using the .Contains() method in linq-to-sql. Thanks. 回答1: What you have is correct. This will be translated into an IN

Update item in IEnumerable

寵の児 提交于 2020-07-18 03:35:52
问题 I need to update a value in a IEnumerable list. Here is a brief IEnumerable example: IEnumerable<string> allsubdirs = new List<string>() { "a", "b", "c" }; Now if I want to add a timestamp to each item, this doesnt work: allsubdirs.Select(a => a = a + "_" + DateTime.Now.ToString("hhmmss")).ToList(); Neither does this: foreach (var item in allsubdirs) item = item + "_" + DateTime.Now.ToString("hhmmss"); I made it work like this: IEnumerable<string> newallsubdirs = allsubdirs.Select(a => a + "_

Group List of Objects based on Property using Linq?

╄→尐↘猪︶ㄣ 提交于 2020-07-18 03:32:08
问题 I have an object: public class SiteInfo { public string Title { get; set; } public string URL { get; set; } public string Type { get; set; } } That I am using to create a list: var sites = new List(); foreach (SPWeb site in web.GetSubwebsForCurrentUser()) { string sitetype = getConfigurationKey(site, "siteType"); //If sites have a site type then add to list if (sitetype != "*ERROR*" && sitetype != "*KEYNOTFOUND*") { SiteInfo s = new SiteInfo(); s.Title = site.Title; s.URL = site.Url; s.Type =

Find Gap Date Ranges from two Set of Date Ranges C#

南楼画角 提交于 2020-07-18 01:44:43
问题 I have Base date Ranges and Test Date Range. I need to get GAP between base and test meaning Missing Date Ranges that are in Base but not in Test. what would be the best way to do this? Base Date Ranges 1/1/2012 1/10/2012 1/11/2012 1/25/2012 Test Date Ranges 1/2/2012 1/7/2012 1/8/2012 1/9/2012 1/15/2012 1/30/2012 Output: Missing Date Ranges that are in Base but not in Test 1/1/2012 1/2/2012 1/7/2012 1/8/2012 1/9/2012 1/10/2012 1/11/2012 1/15/2012 Tried this so far static void Main(string[]

Find Gap Date Ranges from two Set of Date Ranges C#

隐身守侯 提交于 2020-07-18 01:40:55
问题 I have Base date Ranges and Test Date Range. I need to get GAP between base and test meaning Missing Date Ranges that are in Base but not in Test. what would be the best way to do this? Base Date Ranges 1/1/2012 1/10/2012 1/11/2012 1/25/2012 Test Date Ranges 1/2/2012 1/7/2012 1/8/2012 1/9/2012 1/15/2012 1/30/2012 Output: Missing Date Ranges that are in Base but not in Test 1/1/2012 1/2/2012 1/7/2012 1/8/2012 1/9/2012 1/10/2012 1/11/2012 1/15/2012 Tried this so far static void Main(string[]

IQueryable<T> gives different result than a List<T>

独自空忆成欢 提交于 2020-07-15 10:16:21
问题 If I use Select on IQueryable on my entity framework result I'll get 4 items as a result. If I use Select on an IQueryable.ToList() I get all 36 items. Here's code of the function: public ImagesGetModelView Get(int start, int count) { if (count <= 0) count = 9; else if (count > ImageHandler.MaxResult) count = ImageHandler.MaxResult; IQueryable<Image> imagesList = ImagesHandler.FetchRangeScore(start, count) .Where(m => m.Domain == Database.Enums.ImageDomain.Gfycat); //Works using list :( //var

IQueryable<T> gives different result than a List<T>

可紊 提交于 2020-07-15 10:15:51
问题 If I use Select on IQueryable on my entity framework result I'll get 4 items as a result. If I use Select on an IQueryable.ToList() I get all 36 items. Here's code of the function: public ImagesGetModelView Get(int start, int count) { if (count <= 0) count = 9; else if (count > ImageHandler.MaxResult) count = ImageHandler.MaxResult; IQueryable<Image> imagesList = ImagesHandler.FetchRangeScore(start, count) .Where(m => m.Domain == Database.Enums.ImageDomain.Gfycat); //Works using list :( //var