linq

How to combine two flat lists into one nested object

隐身守侯 提交于 2020-07-03 11:51:31
问题 I have three lists which contains three same properties in each collection. I want to combine a result into one collection. Ex classes structure is as below public class Order { public int ProductId { get; set; } public int CustomerId { get; set; } public int OrderId { get; set; } // Few other Properties of OrderDetail } public class PaymentDetail { public int ProductId { get; set; } public int CustomerId { get; set; } public int OrderId { get; set; } // Few other Properties form

Querying Json as string within a property of an object using linq

二次信任 提交于 2020-06-29 05:11:31
问题 I have this: public partial class spGetProductsFilter_Result1 { public int P_Id { get; set; } public string P_JsonData { get; set; } public Nullable<int> P_SC_Id { get; set; } public string P_Title { get; set; } public int SC_Id { get; set; } public Nullable<int> SC_C_Id { get; set; } public string SC_Name { get; set; } public string SC_Image { get; set; } public int C_Id { get; set; } public string C_Name { get; set; } public string C_Image { get; set; } } As you can see that the json (P

C# Entity Framework: Linq Filter on GrandChildren and Conduct a Select on the Parent with Attributes

烈酒焚心 提交于 2020-06-29 03:42:31
问题 Our company is currently using Entity Framework Net Core 2.2 with Sql Server Trying to find all Distinct customers who purchased a certain Product Input Parameter . The following EF Linq query was written to get the distinct Customers. Later another question came up, how do we get more (navigation) properties of customer? Should Include be placed Before the Where or After the Where? Does it matter? When running the SQL Profiler, it noted no difference in the queries. I just wanted to be sure

How do I convert Dataset to model <T> - for excel data driven tests

青春壹個敷衍的年華 提交于 2020-06-29 03:41:38
问题 I have fetched data from excel sheet and it is having all the values in Dataset now I ave DataModel type List and I want to return that type and then fetch data but I'm finding difficulty in that public class TestDataModel { public TestDataModel() { } [DataNames("TestName")] public string TestName { get; set; } [DataNames("productId")] public int productId { get; set; } [DataNames("orderId")] public int orderId { get; set; } [DataNames("designMethod")] public string designMethod { get; set; }

Compare 2 List using Except [duplicate]

纵饮孤独 提交于 2020-06-29 03:39:14
问题 This question already has answers here : LINQ Except not working as expected [duplicate] (1 answer) LINQ Except() Method Does Not Work (4 answers) Using Linq Except not Working as I Thought (4 answers) Closed 2 years ago . I have 2 List<Animal> which I would like to compare and find the difference between the 2 List<Animal> objects. Animal object contains the following properties. Id Name Age List list1 has a count of 10 Animal objects in it, where as list2 has another 10 Animal objects in it

No applicable method 'Select' exists in type 'DataRow'

天涯浪子 提交于 2020-06-29 03:32:13
问题 I have a data table result and I converted it to Enumerable using AsEnumerable extension. var dataTableToEnumerable = dataTable.AsEnumerable(); Now Im doing a groupBy on it using Linq Dynamic Extensions and it works fine but I cant process Select() , Sum() , Min() etc on the aggregrated result. But methods like Count(),First(),FirstOrDefault() exist. dataTableToEnumerable.AsQueryable().Where("(it[\"yoko\"] != null&&it[\"price\"] != null)") .GroupBy("new(it[\"proposalid\"] as proposalid,it[\

dispose bitmap in an array using linq

北慕城南 提交于 2020-06-28 08:34:17
问题 I have an array of 3500 bitmaps. These bitmaps are displayed on the screen (a screen can display 12) and more are loaded while the vertical scroll bar is going down. At some point, i would like to release these images from memory and i'd like to know if Linq can help : What i tried : Declaration : imageCache = new Bitmap[someCountWithaResultOf3500]; The imageCache gets loaded by images and then at some point i would like to dispose a few (from the beginning to 200 before the current one). Id

what is the mechanism for performing an intersect in a Mongo Linq query

你离开我真会死。 提交于 2020-06-28 07:28:25
问题 How do I write a where clause in Linq for Mongo to determine if any member of a local collection is contained by a collection in my document. i.e. (this was what I was expecting to work, but didn't) var myLocalList = <PopulateMyLocalList>; var myDocs = db.GetCollection<MyDoc>("MyDocs").AsQueryable(); var result = myDocs.Where(d => d.MyCollection.Intersect(myLocalList).Any()); So assuming that the Mongo Linq provider does not support this - How do I go about it? 回答1: In MongoDB syntax there's

C# Entity Framework: Linq Filter on GrandChildren and Conduct a Select on the Parent

て烟熏妆下的殇ゞ 提交于 2020-06-28 06:41:21
问题 Our company is currently using Entity Framework Net Core 2.2 with Sql Server Trying to find all Distinct customers who purchased a certain Product Input Parameter. When trying to do final select, it shows b lambda as Product. We need the Distinct Customers showing up last. How the EF Linq query be written to get this for distinct Customers? var taxAgencyDistinctList = db.Customer .SelectMany(b => b.Transactions) .SelectMany(b => b.Purchases) .Select(b => b.Product) .Where(b => b.BKProduct ==

C# query with dynamic tablename

爷,独闯天下 提交于 2020-06-28 06:34:10
问题 I want to build a query where the tablename will be dynamic and I will get it from another query. The 2 queries are in different datacontexts. CODE var tablename = (from tab in db.Tabs where tab.id == tabid select tab.name).FirstOrDefault(); var pid = (from p in tablename select p.id).FirstOrDefault(); 回答1: using(SqlConnection sqlCon = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) { SqlCommand com = new SqlCommand();