c# - LINQ: How to null out properties in a projection? -


The title is very awesome, so try to explain it in code. I have a unit named Change and has a collection of institutions in the ChangeDetail I want to store the Change > ChangeListItem is called . I'm roaming with LINQPad and have actually launched and I want to work, but whatever I can not do, leave all those people in the group except ChangeListItem s. Here's my code:

Change the Change category

  public class: {Receive the public date time change time; Set; } # Area Navigation Properties Public Virtual IcLonac & lt; ChangeDetail & gt; Details {Receive; Private set; } #endregion Public Changes () {this.Details = New list & lt; ChangeDetail & gt; (); }}   

ChangeDetail class

  public class ChangeDetail {public string description {get; Set; } #region Navigation Properties Public int ChangeId {get; Set; } Change public virtual changes {get} Set; } #endregion}   

My linppad attempt

  var change = change Select Selection (C => C. Description). Orderbodsciding (C => C.Change.ChangedDateTime). Select (C => New ChangeListItem {ChangedDateTime = c.Change.ChangedDateTime, Description = c.Details}) .GroupBy (c => c.ChangedDateTime) .Pre (G = & gt; { (1). Firstly, when I put it in the result pane, I still see the  ChangeListItem < / Code>, but the  ChangedDateTime  property is still loaded out. I'm sure I'm missing an assignment somewhere on the way, even if I thought what I would do I'm good enough How can I get it?  

Png "alt =" Enter image details here ">

To do this:

Enter image details here

Update Requested, here is the ForEach extension for code:

  Public Stable Class IQueryableExtensions {Public Stable IQueryable & lt; T & gt; for AEH & lt ; T & gt; (This IEnumerable & lt; T & gt; source, action & lt; T & gt; action) {if (source == null) {new argument (NullException) ("source"); } If (action == faucet) {new binary NullException ("action"); } Leading (TT in Source) {Action (T); } Return Source. Eskenable & lt; T & gt; (); }}    

treat you as a LINQ query Although it was an archive I think your ForEach extension looks like this:

  foreach (various items in the source ) {Side effects (item); } Return source;   

The result of the query here is calculated once, and each of its result formats is mutated. But then when you calculate the query again, the result is resuscitated from scratch; As a result, the mutation is 'lost'.

In theory, it would be possible to include some strategic call to call toList () to get the desired effect. But it is not in the spirit of LINQ. Do not mix LINQ and side effects If you want to project some items conditionally and do not want to leave others untouched, then do this:

  changeGroup.Select ((c, Index) = & gt; Index == 0? C: new ChangeListItem {Time changed = zero, details = c.Details});   

BTW, you may need to call asenumerable () before making this change because I do not think LINQ supports the entity's overload Is Select which includes the item index (though, can not remember hand-hand).

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -