小编Nin*_*Nye的帖子

带有"OR"子句的通用表达式树,用于每个提供的属性

我为IQueryable创建了一个通用搜索扩展方法,使您可以搜索单个属性以查看其中是否包含搜索词.

http://jnye.co/Posts/6/c%23-generic-search-extension-method-for-iqueryable

我现在想让用户选择多个属性来搜索每个属性,匹配是否有任何属性包含文本.

代码:

用户输入以下代码以执行此搜索:

string searchTerm = "Essex";
context.Clubs.Search(searchTerm, club => club.Name, club => club.County)

//Note: If possible I would rather something closer to the following syntax...
context.Clubs.Search(club => new[]{ club.Name, club.County}, searchTerm);
// ... or, even better, something similar to this...
context.Clubs.Search(club => new { club.Name, club.County}, searchTerm);
Run Code Online (Sandbox Code Playgroud)

这将返回任何名为"Essex"的高尔夫俱乐部或郡.

    public static IQueryable<TSource> Search<TSource>(this IQueryable<TSource> source, string searchTerm, params Expression<Func<TSource, string>>[] stringProperties)
    {
        if (String.IsNullOrEmpty(searchTerm))
        {
            return source;
        }

        // The lamda I would like to reproduce: …
Run Code Online (Sandbox Code Playgroud)

c# generics lambda expression-trees

5
推荐指数
1
解决办法
984
查看次数

MVC2到MVC3 IOC问题

我刚刚从MVC2迁移到MVC3,我在构建项目时遇到以下错误:

RhinoIoCControllerFactory没有实现接口成员System.Web.Mvc.IControllerFactory.GetControllerSessionBehavior(System.WebRouting.RequestContext,string)

这是错误来自的类别:

        public class RhinoIoCControllerFactory : IControllerFactory
        {

            public IController CreateController(RequestContext requestContext, string controllerName)
            {
                return IoC.Resolve<IController>((controllerName + "Controller").ToLower());
            }

            public void ReleaseController(IController controller)
            {
                IoC.Container.Release(controller);
            }

        }
Run Code Online (Sandbox Code Playgroud)

有任何想法吗 ?

谢谢

ioc-container asp.net-mvc-3

4
推荐指数
1
解决办法
1475
查看次数