I’ve looked everywhere on the internet. What I’ve found is that people use Entity’s framework to communicate with the Database. There’s is a function in this framework called Any<> that mimics Contains() SQL method. I tried to implement the ANY<> method but it doesn’t work. It kept giving me conversion type errors.
So my question is this… what is the CORRECT way of implementing ANY<> function. Hope some guru can answer soon. Thanks in advance!
–
So just for some context, I had something like this:
public static List<PhotoAlbumDto> searchAlbumsFromDA(string inputName)
{
EzPrintsEntities db = new EzPrintsEntities();
List<PhotoAlbum> albums = db.PhotoAlbums.ToList().Any(b => b.NAME == inputName);
}
The second like would throw me an :
Error 14 Cannot implicitly convert type ‘bool’ to ‘System.Collections.Generic.List’ C:\Users\cding\Documents\Visual Studio 2010\Projects\ConsoleApplication6\EZP.Album.Data\PhotoAlbumDA.cs 22 39 EZP.Album.Data
I think I know the reason why this is giving me an error, but I don’t know how to fix it. I’m simply trying to search the database for any PhotoAlbum Objects that matches a certain name.
EDIT: New Question: How do you use Where<> to search for things that match to part of it?
For Example:
User wants to search up: funny
then my search function will return anything that has the word “funny” in it, such as funnygirls, funnydogs, funnypeople, funnybikes, etc…
I implemented the Where<>, but i doesn’t do the feature above? Is there any fixes? or any Alternatives?
Why are you wanting to use any? Any will return a boolean of is there anything in the DB that matches this? Think of it like this:
Any: Does anything in my list match this?
Where: Give me anything in my list that matches this.
I think you’re actually wanting where: