RobThree / MongoRepository

Repository abstraction layer on top of Official MongoDB C# driver
https://www.nuget.org/packages/MongoRepository/
MIT License
307 stars 141 forks source link

Unable to determine the serialization information for the expression #27

Closed zhujinhu21 closed 8 years ago

zhujinhu21 commented 8 years ago

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 26578-20160225224407411-1394691890

data model is

qq 20160226191302

What is the problem? Thanks.

RobThree commented 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:

RobThree commented 8 years ago

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

zhujinhu21 commented 8 years ago

`` thanks AddressBookMessage store in mongo,and it's property MsgBody is class. code.zip

zhujinhu21 commented 8 years ago

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 ); }

zhujinhu21 commented 8 years ago

I use you code var msgList2 = repo.Where(m => m.news.Any(n => n.title.Contains("foo"))).ToList(); and it woks.thank you

RobThree commented 8 years ago

You're welcome.