简体   繁体   中英

Advanced Search with linq To sql

I'm working on my first ASP.net MVC apps, in this apps i got to type of search Simple and Advanced :

Simple search olny dd,df and gov are required
Advanced search user got more options, even in advanced search dd,df and gov are required field.

So this is my Search Action

[HttpPost]
    public ActionResult search(LogModel.Search soption)
    {
        // this part will not change the same in simple and advenced
        DateTime dd1 = soption.dd;
        DateTime df1 = soption.df;
        var model = (from p in entity.vehicule                        
                     where p.agence.idgov == soption.gov
                     where !p.indisponible.Any(b => (dd1 >= b.Dd && dd1 <= b.Df) || (df1 >= b.Dd && df1 <= b.Df))
                     where !p.indisponible.Any(c => (c.Dd >= dd1 && c.Dd <= df1) || (c.Df >= dd1 && c.Df <= df1))
                     select p).ToList();


        // here i want to add my filtring action advanced search
        if (!soption.mark)
            model = model.Any(b => b.idmarque == soption.mark );


        return View(model);

    }

the simple search mode work so fine but now i'm trying to implement the advanced search and this is what i got in my mind :

If model.myVar is not null(that mean user has puted something )
then i'm gonna filter some result from my pricinple model search request.

So I'm wondring if i got right ? also this line is underlined with red :

model = model.Any(b => b.idmarque == soption.mark );

Impossible to convert type bool to Systeme.collection.generic.list

Just use a where clause again

if (!soption.mark) 
            model = from x in model
                    where (b => b.idmarque == soption.mark )
                    select x

Any() method of model returns bool. You can try select()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM