Help with LINQ statement

Help with LINQ statement

Old forum URL: forums.lhotka.net/forums/t/6276.aspx


Jack posted on Wednesday, January 28, 2009

I am using the following function to return the subset of my collection that is dirty.  At the same time I want to set my updateId/updateDate properties.

internal IQueryable<DataField> GetDirtyDataFields(string updateId, DateTime updateTimeStamp)
        {
            var dirtyData = (from DataField df in this.DataFields where df.IsDirty && !df.IsNotApplicable select df);

            foreach (DataField df in dirtyData)
            {
                df.UpdatorId = updateId;
                df.UpdateDate = updateTimeStamp;
            }

            return dirtyData;
        }

Is there a way to combine the foreach statement into my LINQ statement such that I do an update and return the list in one pass?

Thanks

jack

Copyright (c) Marimer LLC