Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-651

Support LINQ Cast operator.

    XMLWordPrintableJSON

Details

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Minor - P4 Minor - P4
    • None
    • 1.7
    • Linq
    • None
    • Fully Compatible

    Description

      In LINQ2SQL I could wrote:

      public static int? GetIDByHash(this IQueryable<Picture> source, byte[] hash)
      {
      	return
      		source
      			.Where(p_ => p_.Hash == hash)
      			.Select(p_ => (int?)p_.ID)
      			.SingleOrDefault();
      }

      But in LINQ in MongoDB i can't do this. I have to do so:

      public static int? GetIDByHash(this IQueryable<Picture> source, byte[] hash)
      {
      	var pic = source.SingleOrDefault(p => p.Hash == hash);
      	return pic != null ? pic.ID : default(int?);
      }

      This saddens me.

      The same issue appears with the Cast<int?>() operator.

      Attachments

        Activity

          People

            Unassigned Unassigned
            engenyn Evheny Nemov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: