SHARE
TWEET

Untitled

a guest May 19th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace LINQDictionaryJoin
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var bl = new IPersonBasicBL();
  12.             var result = bl.Get();
  13.  
  14.             new IPersonChangeContentBL().SetPersonInfo(result);
  15.  
  16.         }
  17.     }
  18.  
  19.     public class IPersonBasicBL
  20.     {
  21.         public IEnumerable<Person> Get()
  22.         {
  23.             List<Person> result = new List<Person>();
  24.             result.Add(new Person { Id = 1, Name = "Name", ChangeContentId = new Guid(), EffectiveDate = DateTime.Today });
  25.             return result;
  26.         }
  27.     }
  28.  
  29.     public interface IPersonBasic
  30.     {
  31.         int Id { get; set; }
  32.         string Name { get; set; }
  33.     }
  34.  
  35.     public class IPersonChangeContentBL
  36.     {
  37.         public void SetPersonInfo(IEnumerable<IPersonChangeContent> datas)
  38.         {
  39.             var ids = datas.Select(d => d.ChangeContentId);
  40.             var personChangeContentDict = new PersonChangeContentRepository()
  41.                                                 .Get(ids)
  42.                                                 .ToDictionary(n => n.ChangeContentId);
  43.  
  44.             foreach (var item in datas)
  45.             {
  46.                 item.EffectiveDate = personChangeContentDict.GetValue(item.ChangeContentId).EffectiveDate;
  47.             }
  48.         }
  49.     }
  50.  
  51.     public class PersonChangeContentRepository
  52.     {
  53.         internal IEnumerable<IPersonChangeContent> Get(IEnumerable<Guid> ids)
  54.         {
  55.             List<IPersonChangeContent> result = new List<IPersonChangeContent>();
  56.             result.Add(new Person { Id = 1, Name = "Name", ChangeContentId = new Guid(), EffectiveDate = DateTime.Today });
  57.             return result;
  58.         }
  59.     }
  60.  
  61.     public interface IPersonChangeContent
  62.     {
  63.         Guid ChangeContentId { get; set; }
  64.         DateTime EffectiveDate { get; set; }
  65.     }
  66.  
  67.     public class Person : IPersonBasic, IPersonChangeContent
  68.     {
  69.         public int Id { get; set; }
  70.         public string Name { get; set; }
  71.  
  72.         public Guid ChangeContentId { get; set; }
  73.         public DateTime EffectiveDate { get; set; }
  74.     }
  75.  
  76.     public static class Helers
  77.     {
  78.         public static T2 GetValue<T1, T2>(this Dictionary<T1, T2> dict, T1 key)
  79.         {
  80.             T2 result = default(T2);
  81.  
  82.             dict.TryGetValue(key, out result);
  83.  
  84.             return result;
  85.         }
  86.     }
  87. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top