• 0

Can't figure out how to search by array


Question

I have about a few hours of experience (code first).

I cannot figure out how to get a single element out by its hash:

 

                UserAgent userAgent =
                    db
                    .UserAgents
                    .FirstOrDefault(ua => ua.Hash.SequenceEqual(uaHash));
This crashes saying that SequenceEqual is unsupported or some such Linq To Sql jibberish.

Of course I can get all the elements out of the DB and then do an unsafe UInt64 binary comparison.

But that is nasty O(n) each time.

I am attempting to store IP addresses and Hashes (for fast lookup) in DB.

 

        [Required]
        [MaxLength(16)] // 128 - IP6
        [MinLength(4)] // 32 - IP4
        public byte[] Ip { get; set; }
        [Required]
        public byte[] Hash { get; set; }
Ofc I can try simply writing old fashioned SQL queries, but that just kills the nice aspect of having a model automatically generated for you via POST, validated, and saved with a few lines of code.
Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

What's the exact error message received?

Just says that it is not supported by Linq to Sql.

 

Just asking what is the proper way to search like "WHERE hash = 0x2FF4" using EF/L2SQL? Or is the whole framework still in its infancy and should be avoided?

Link to comment
Share on other sites

  • 0

I believe that it's .where(x = x.field => value);

 

edit: Check this page out: http://www.dotnetperls.com/where

Nope,

http://stackoverflow.com/questions/713341/comparing-arrays-in-c-sharp

EDIT: Although, does EF actually do a genuine comparison when using .Where(x => x == value) where x is an enumeration?

Link to comment
Share on other sites

This topic is now closed to further replies.