LAffair
LAffair

Reputation: 1998

An expression tree may not contain a dynamic operation - linq

I have a simple query,

            var RoundList = (from t1 in entities.RPlays.AsNoTracking()
                             where t1.Start.ToString("d") == "01/03/2017" && t1.VId == 32
                             select new
                             {
                                 TimePlayed = t1.TimePlayed,
                                 MatchPlayed = t1.MatchPlayed 
                             });

that gets me the message "An expression tree may not contain a dynamic operation" but it doesn't say where :(

I get the problem on the where line.

What am I doing wrong?

Upvotes: 0

Views: 4073

Answers (1)

Ofir Winegarten
Ofir Winegarten

Reputation: 9365

This is due to the ToString("d").

You should try to just compare dates like this:

        DateTime myDate = DateTime.Parse("2017-03-01");
        var RoundList = (from t1 in entities.RPlays.AsNoTracking()
                         where t1.Start == myDate && t1.VId == 32
                         select new
                         {
                             TimePlayed = t1.TimePlayed,
                             MatchPlayed = t1.MatchPlayed 
                         });

Upvotes: 2

Related Questions