Closed zhujinhu21 closed 8 years ago
The problem is that the mongo-csharp-driver can't convert your expression to a MongoDb query. I would try to reproduce and maybe figure out if there's an easy workaround / fix for this but I can't copy/paste code from screenshots and I'm lazy :wink:
As said; I don't have enough code in the above screenshots to reproduce but something like this should work:
var msgList2 = repo.Where(m => m.news.Any(n => n.title.Contains("foo"))).ToList();
Here's a simple sample I used to (try to) reproduce your problem as best I could: TMDB.zip
`` thanks AddressBookMessage store in mongo,and it's property MsgBody is class. code.zip
MongoRepository<AddressBookMessage> messageRepository = new MongoRepository<AddressBookMessage>(); public IHttpActionResult Search(string keyword) { var msgList = messageRepository.Where(m => m.MsgBody.news.Select(s => s.title).Contains(keyword)).ToList(); return Ok(msgList ); }
I use you code var msgList2 = repo.Where(m => m.news.Any(n => n.title.Contains("foo"))).ToList(); and it woks.thank you
You're welcome.
Unable to determine the serialization information for the expression: Enumerable.Select<News, String>(m.MsgBody.news, (News s) => s.title).
I user mongocsharpdriver 1.10.1 .mongodb 3.0 server. my search code is var msgList2 = messageRepository.Where(m => m.MsgBody.news.Select(s => s.title).Contains(keyword)).ToList();
collection structure is
data model is
What is the problem? Thanks.