using System.Collections.Generic;
public static void Main()
var itemAttrValues = new List<ItemAttributeItemCodeAssignDto>
new ItemAttributeItemCodeAssignDto {NumericValue = 0.00, StringValue = "Y", DateValue= "0001-01-01", EffectiveDate= "2019-04-30", TerminationDate= "9999-12-31",
FK_ItemAttributeGroupCode= 4, FK_ItemAttributeCode = 2, FK_ItemCode= 1753,
FK_LocationId= null, FK_PermittedAttributeGroupCode= 4, FK_PermittedAttributeCode= 2, FK_PermAttrSequenceNumber= 1, FK_FacilityNumber= null,
LastUpdatedOn= DateTime.Parse("2018-08-27 16:37:20.990000"), LastUpdatedBy= "viju", CreatedOn= "2018-08-27 16.37.20.990006", CreatedBy= "vamshi"},
new ItemAttributeItemCodeAssignDto {NumericValue = 0.00, StringValue = "Y", DateValue= "0001-01-01", EffectiveDate= "2018-05-25", TerminationDate= "2019-04-29",
FK_ItemAttributeGroupCode= 4, FK_ItemAttributeCode = 2, FK_ItemCode= 1753,
FK_LocationId= null, FK_PermittedAttributeGroupCode= 4, FK_PermittedAttributeCode= 2, FK_PermAttrSequenceNumber= 1, FK_FacilityNumber= null,
LastUpdatedOn= DateTime.Parse("2018-08-27 16:37:20.990000"), LastUpdatedBy= "viju", CreatedOn= "2018-08-27 16.37.20.990009", CreatedBy= "vamshi"}
IEnumerable<ItemAttributeItemCodeAssignDto> itmAttrItmCodesAssignValues= itemAttrValues as IEnumerable<ItemAttributeItemCodeAssignDto>;
itmAttrItmCodesAssignValues = itmAttrItmCodesAssignValues.Where(x => x.FK_ItemAttributeGroupCode == 4 && x.FK_ItemAttributeCode == 2);
if (itmAttrItmCodesAssignValues.Count() > 0)
var ItemAttributeCodeAssignWithYTermValues = from IAIA in itmAttrItmCodesAssignValues
where IAIA.FK_PermAttrSequenceNumber == 1 && DateTime.Parse(IAIA.TerminationDate) < DateTime.Today
join SUB in (from p in itmAttrItmCodesAssignValues
p.FK_ItemAttributeGroupCode,
FK_ItemAttributeGroupCode = g.Key.FK_ItemAttributeGroupCode,
FK_ItemAttributeCode = g.Key.FK_ItemAttributeCode,
FK_ItemCode = g.Key.FK_ItemCode,
MaxDate = g.Max(x => x.CreatedOn)
IAIA.FK_ItemAttributeGroupCode,
IAIA.FK_ItemAttributeCode,
SUB.FK_ItemAttributeGroupCode,
SUB.FK_ItemAttributeCode,
select new ItemAttributeItemCodeAssignDto
NumericValue = IAIA.NumericValue,
StringValue = IAIA.StringValue,
DateValue = IAIA.DateValue,
EffectiveDate = IAIA.EffectiveDate,
TerminationDate = IAIA.TerminationDate,
FK_ItemAttributeGroupCode = IAIA.FK_ItemAttributeGroupCode,
FK_ItemAttributeCode = IAIA.FK_ItemAttributeCode,
FK_ItemCode = IAIA.FK_ItemCode,
FK_LocationId = IAIA.FK_LocationId,
FK_PermittedAttributeGroupCode = IAIA.FK_PermittedAttributeGroupCode,
FK_PermittedAttributeCode = IAIA.FK_PermittedAttributeCode,
FK_PermAttrSequenceNumber = IAIA.FK_PermAttrSequenceNumber,
FK_FacilityNumber = IAIA.FK_FacilityNumber,
LastUpdatedOn = IAIA.LastUpdatedOn,
LastUpdatedBy = IAIA.LastUpdatedBy,
CreatedOn = IAIA.CreatedOn
foreach(var x in ItemAttributeCodeAssignWithYTermValues)
Console.WriteLine(x.CreatedOn);
public class ItemAttributeItemCodeAssignDto
public double NumericValue { get; set; }
public string StringValue { get; set; }
public string DateValue { get; set; }
public string EffectiveDate { get; set; }
public string TerminationDate { get; set; }
public int FK_ItemAttributeGroupCode { get; set; }
public int FK_ItemAttributeCode { get; set; }
public int FK_ItemCode { get; set; }
public string CreatedOn { get; set; }
public string CreatedBy { get; set; }
public string LastUpdatedBy { get; set; }
public DateTime LastUpdatedOn { get; set; }
public int? FK_LocationId { get; set; }
public int? FK_PermittedAttributeGroupCode { get; set; }
public int? FK_PermittedAttributeCode { get; set; }
public int? FK_PermAttrSequenceNumber { get; set; }
public int? FK_FacilityNumber { get; set; }