Nhibernate 4 API文档 [英] Nhibernate 4 API documentation

查看:72
本文介绍了Nhibernate 4 API文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到哪个名称空间包含哪些方法.

I am not able to find which namespace contains what for methods.

  • 例如NHibernate.IQueryOver不包含添加"的定义 并且没有扩展方法'Add'接受类型为.
  • 的第一个参数.
  • e.g. NHibernate.IQueryOver does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type .

由于扩展方法的存在,Visual Studio无法帮助找到合适的使用方法.

Visual studio is not helping to get appropriate method on using because of extension method.

我怎么知道应该包括哪些方法和名称空间?

How can I know which methods, namespaces should be included?

推荐答案

如果我们想将QueryOver传递给另一个方法,并对其执行一些过滤,则必须知道传递的类型.

In case, that we want to pass QueryOver into another method, and execute some filtering over it, we MUST know the type, which is passed.

下面的代码片段显示,我们有一些已知的接口 IBusinessObject ,该接口具有ID和Name.这可能有助于为通用参数T和U创建where条件-并应用一些与该接口相关的东西:

Below snippet shows, that we have some known interface IBusinessObject, which has ID and Name. That could help use to create where conditions for our generic params T and U - and apply some stuff related to that interface:

using NHibernate.Criterion;

namespace MyNamespace
{
    public interface IBusinessObject
    {
        int ID { get; }
        string Name { get; }
    }

        public static QueryOver<T, U> AddSomeFilter<T, U>(QueryOver<T, U> queryOver)
            where T: IBusinessObject
            where U: IBusinessObject
        {
            // here we can play with ID, and Name
            // because we know that U is of a type IBusinessObject
            queryOver
                .Where(x => x.ID > 1)
                .Where(x => x.Name == "Abc");

            return queryOver;
        }
    }
}

可以,但是可能导致某些依赖性.这就是为什么我老实地喜欢使用Criteria API的原因.我们可以传递一些元数据,并创建更多动态处理器:

This could be fine, but it could lead to some dependency. That's why I honestly do like to use Criteria API. We can pass some Metadata, and create more dynamic processors:

public static class MyExtension
{
    public static ICriteria AddLike(ICriteria criteria, string property, string likeValue)
    {
        if (property.IsNotEmpty())
        {
            criteria.Add(Restrictions.Like(property, likeValue));
        }
        return criteria;
    }

要处理注释中的方法,我们可以这样做:

To process the method in the comment, we can do it like this:

public class SearchCriteria
{
    public string PropertyName { get; set; }
    public string LikeValue { get; set; }
}

public static class MyExtension
{
   public static IQueryOver<Employee, Employee> ConstructQueryConditions(
        this IQueryOver<Employee, Employee> query
        , SearchCriteria criteria)
    {
        if (criteria.PropertyName.IsNotEmpty())
        {
            query.Where(Restrictions.Like(criteria.PropertyName, criteria.LikeValue));
        }
        return query;
    }

这篇关于Nhibernate 4 API文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆