ienumerable

Return a viewmodel with IEnumerable's to view and use razor to loop variables into the same row

大兔子大兔子 提交于 2019-12-13 07:28:37
问题 In a razor view, how can I loop through different IEnumerables in a ViewModel and display their variables as columns in the same row? I Return an instance of a viewmodel which is populated with IEnumerables of different models to a mvc view like so: Viewmodel: namespace example.ViewModels { public class ClaimModel { public IEnumerable<Claim> Claims { get; set; } public IEnumerable<Member> Members { get; set; } public IEnumerable<ID> IDs { get; set; } } } My controller which return the view

Changing value of one item in a collection affects all duplicate items

假装没事ソ 提交于 2019-12-13 06:32:51
问题 I seem to be having an odd issue whereby every time I try to change a value of an item in a collection, it affects all others that contain the same initial values. An example is below: public class Product : ICloneable { public int Id { get; set; } public string Name { get; set; } public int Quantity { get; set; } public Product() { Id = 0; Quantity = 0; } public Clone() { return (Product)this.MemberwiseClone(); } } ... private static IEnumerable<Product> GetProducts(Product product, int

C# Linq where clause .Contains(string[])

会有一股神秘感。 提交于 2019-12-13 04:44:53
问题 Ive been googling for the last few hours to find a solution to my problem but im stumpped. I was wondering if someone could help me out with the following. I have a Linq query that queries against a DataTable. I have a param of string[] BodyTypes that holds strings like "5,7,11" or "6,7,4" or just "5," the Linq i have is: var query2 = (from v in query.AsEnumerable() where (from yy in BodyTypes select yy).Contains(v.Header36.ToString()) select new { PartNumber = v.PartNumber, Position = v

Why IEnumerable.ToList() return fields in alphabetical order?

旧巷老猫 提交于 2019-12-13 04:41:14
问题 I have this simple function in a class that return IENumerable Colection using LINQ projection: public IEnumerable<Pedidos> Pedidos_Listar(string sComprobante, Clientes MyCliente = null, DateTime? dDesde = null, DateTime? dHasta = null, bool bCumplidos = false) { using (var context = new OhmioEntities()) { return (from Pedidos in context.Pedidos join Clientes in context.Clientes on Pedidos.ID_Cliente equals Clientes.ID_Cliente where Pedidos.ID_Comprobante == sComprobante select Pedidos)

Find Same Values Between 2 ArrayList And Return As Another ArrayList

爱⌒轻易说出口 提交于 2019-12-13 03:53:53
问题 I am trying to extract the values shared by two arraylist into another arraylist. using System.Linq; private ArrayList GetSameOf2AL(ArrayList first, ArrayList second) { ArrayList same = new ArrayList(); var one = from int i in first select i; var two = from int i in second select i; var SameVal = one.Intersect(two); //I am supposed to convert or cast SameVal into arraylist here return same; } My questions are: I couldn't convert the var type back into arraylist , can someone advise me how?

One call main, multiple responses in ASP.NET MVC + angular 6

人走茶凉 提交于 2019-12-13 02:26:32
问题 First of all, I have no idea if this is possible! and I'm struggling to find an answer. I think I don't know what to search for! I have an endpoint that returns IEnumerable , I want to divide the response so I used .Skip().Take() Now when I get the first take, how can I get the second one without invoking the same endpoint! The problem is IEnumerable gets the data from another service where it is not possible to divide, so I have to get everything at once and then I have to call another "SLOW

Iterating over IEnumerable using foreach skips some elements

主宰稳场 提交于 2019-12-13 01:36:14
问题 I've faced with difference in behavior between iterating over enumerable and over enumerable.ToList() . public static void Kill(Point location) { Wound(location); foreach(var point in GetShipPointsAndTheirNeighbors(location).ToList()) { CellsWithShips[point.X, point.Y] = false; } } /// <summary> /// This version does not work for strange reasons, it just skips a half of points. See TestKill_DoesNotWork_1 test case /// </summary> /// <param name="location"></param> public static void Kill

Enumerable.Repeat has some memory issues?

人走茶凉 提交于 2019-12-13 00:44:45
问题 I initialized an Array as Double[][] myarr = Enumerable.Repeat(new double[12], 13).ToArray(); Then in a loop i am incrementing values like myarr[0][0]++; This causes all values like myarr[1][0], myarr[2][0], myarr[3][0] ..... myarr[12][0] to increment by one. This problem is not occurring when using a for loop (0-12) i am initializing like myarr[i] = new double[12]; Why is this so? 回答1: Other answers have explained the problem. The solution is to create a new array on each iteration, e.g.

How to access deeply nested array with MongoDB (ASP.NET Core 2.2)

非 Y 不嫁゛ 提交于 2019-12-12 19:36:15
问题 I'm designing an inventory management system with MongoDB. I have the following database structure: inventory └─storage_slots └─storage_locations ...etc... Every time a new Slot is added, a tree representing the slot's location in the hierarchy is added to the storage_locations collection to represent its location (according to location, room, section, shelf). So far I have managed to successfully add a new item where none of the location fields are already used: (The slot is also added to

How to create an HtmlHelper extension method that will bind an IEnumerable<T> to a table

对着背影说爱祢 提交于 2019-12-12 18:26:36
问题 This is my view model: public class TaskViewModel{ public int TaskID{get;set;} public IEnumerable<TaskExecutor> Executors{get;set;} } public class TaskExecutor{ public int ExecutorID{get;set;} public string LastName{get;set;} public string FirstName{get;set;} } In my view I have done something like this: <table> @foreach(var item in Model.Executors) { <tr> <td>item.ExecutorID</td> <td>@string.Format("{0} {1}",item.FirstName,item.LastName)</td> </tr> } </table> Now, when loading the view,