Advertisement
Guest User

LINQ to Entity w/ Guid array

a guest
Jun 5th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement