This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

LINQ to Entity w/ Guid array

By: a guest on Jun 5th, 2013  |  syntax: C#  |  size: 1.48 KB  |  views: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ConsoleApplication1
  5. {
  6.     using System.Collections.Generic;
  7.  
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             var allguids = new List<Guid>();
  13.             for (var i = 0; i < 10; i++)
  14.             {
  15.                 allguids.Add(Guid.NewGuid());
  16.             }
  17.             var requestInfo = new RequestInfo() { VideoIDs = allguids.ToArray() };
  18.  
  19.             var clipVideos = allguids.Take(5).Select(guid => new ClipVideo() { ClipVideoKey = guid }).ToList();
  20.  
  21.             var ve = new VideoCollection() { ClipVideos = clipVideos.AsEnumerable() };
  22.  
  23.             foreach (var guid in requestInfo.VideoIDs)
  24.             {
  25.                 Console.WriteLine("RequestInfo VideoId: {0}", guid);
  26.             }
  27.  
  28.             var first = ve.ClipVideos.FirstOrDefault(x => x.ClipVideoKey == requestInfo.VideoIDs[0]);
  29.             if (first == null)
  30.             {
  31.                 Console.WriteLine("No id found");
  32.             }
  33.             else
  34.             {
  35.                 Console.WriteLine("Clip Video Found: {0}", first.ClipVideoKey);
  36.                
  37.             }
  38.  
  39.             Console.Read();
  40.  
  41.         }
  42.     }
  43.  
  44.     public class ClipVideo
  45.     {
  46.         public Guid ClipVideoKey { get; set; }
  47.     }
  48.  
  49.     public class RequestInfo
  50.     {
  51.         public Guid[] VideoIDs { get; set; }
  52.     }
  53.  
  54.     public class VideoCollection
  55.     {
  56.         public IEnumerable<ClipVideo> ClipVideos { get; set; }
  57.     }
  58. }
clone this paste RAW Paste Data