使用NHibernate生成Crystal Report文档 [英] Generating a Crystal Report document with NHibernate

查看:182
本文介绍了使用NHibernate生成Crystal Report文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用MVVM,Fluent NHibernate,WPF在C#.Net上开发应用程序,我们需要生成一些窗口的报告。我需要使用Crystal Reports工具创建一个报表。 AFAIK,Crystal Reports仅使用DataSet生成报表。在轻而易举的应用程序中,我只能生成一个DataSet,构建报告并使其运行。但是我可以做些什么来使NHibernate低估,或者如何使其工作,使用NHibernate传递数据,而不是创建DataSet,并使此报告直接访问数据库?在一个简短的方式来问:我想使用NHibernate获取的所有数据填充报告。



任何帮助将是欢迎!!!



最好的问候,



Gustavo

解决方案

http://ayende.com/blog/ 2376 / conversion-an-object-collection-to-a-dataset



http://abombss.com/blog/2007/05/09/nhibernate-to-dataset/



你的不是一个新问题。基本上,通常的解决方案是从NHibernate获取信息作为域对象的集合,然后使用这些对象的属性手动构建DataTable。



您还可以将一点香草ADO挂在NHibernate上。 NHibernate ITransactions有一个Enlist()方法,它基本上允许你将一个简单的ADO DbCommand与ADO DbTransaction方式关联在NHibernate的实现中,并按照你不使用NHibernate的方式执行它,以获得结果ADO.NET格式。这里有一些我放入Repository的实现,允许我通过名称调用旧的存储过程:

  public IDataReader ExecuteReaderStoredProcedure(string procName, IUnitOfWork uow,IEnumerable< KeyValuePair< string,object>>参数)
{
var command = Sessions [uow] .Connection.CreateCommand();

command.CommandText = procName;
command.CommandType = CommandType.StoredProcedure;
foreach(参数中的var param)
{
var parameter = command.CreateParameter();
parameter.ParameterName = param.Key;
parameter.Value = param.Value;
command.Parameters.Add(parameter);
}

会话[uow] .Transaction.Enlist(command);
return command.ExecuteReader();
}

然后可以使用DataReader填充DataTable / DataSet。



一些笔记;您看到的IUnitOfWork对象是一个链接到会话及其事务的令牌,用于控制其范围和生命周期;您可以修改此选项,以使用您拥有的任何会话处理机制(包括从SessionFactory创建一个新会话仅适用于此命令,如果您选择)。您还可以传递裸SQL字符串来执行;我通常会避免这种情况(实际上,实际实现中的存储过程的名称被抽象到特定静态类型的常量实例之后,类似于枚举)。


Good evening everyone.

I'm developing a application with MVVM, Fluent NHibernate, WPF on C#.Net, and we need to generate reports of some windows. I need to create a Report using a Crystal Reports tool. AFAIK, Crystal Reports only generate reports with DataSets. In siimple application, i could only generate a DataSet, build the report, and make it run. But how i could do to make NHibernate understant, or how to make it works, passing data with NHibernate, instead of creating a DataSet and make this Report to directly access the database? In a short way to ask: I want to use all data obtained with NHibernate to populate the Report.

Any help will be welcome!!!

Best Regards,

Gustavo

解决方案

http://ayende.com/blog/2376/converting-an-object-collection-to-a-dataset

http://abombss.com/blog/2007/05/09/nhibernate-to-dataset/

Yours is not a new problem. Basically, the usual solution is to get the information from NHibernate as a collection of domain objects, and then manually build a DataTable using the properties of those objects.

You can also bolt a little vanilla ADO onto NHibernate. NHibernate ITransactions have an Enlist() method which basically allows you to associate a plain ol ADO DbCommand to the ADO DbTransaction way down in the bowels of NHibernate's implementation, and execute it as you would if you weren't using NHibernate, to get results in ADO.NET format. Here's something I put into a Repository implementation, allowing me to call legacy stored procedures by name:

    public IDataReader ExecuteReaderStoredProcedure(string procName, IUnitOfWork uow, IEnumerable<KeyValuePair<string, object>> parameters)
    {
        var command = Sessions[uow].Connection.CreateCommand();

        command.CommandText = procName;
        command.CommandType = CommandType.StoredProcedure;
        foreach (var param in parameters)
        {
            var parameter = command.CreateParameter();
            parameter.ParameterName = param.Key;
            parameter.Value = param.Value;
            command.Parameters.Add(parameter);
        }

        Sessions[uow].Transaction.Enlist(command);
        return command.ExecuteReader();
    }

The DataReader can then be used to populate a DataTable/DataSet.

Some notes; the IUnitOfWork object you see is a token that links to a Session and its Transaction, and is used to control their scope and lifetime; you can modify this to use whatever session-handling mechanism you have (including creating a new Session from the SessionFactory just for this command, if you choose). You can also pass in "naked" SQL strings to execute; I typically avoid this (in fact, the names of the stored procs in the actual implementation are abstracted behind constant instances of a particular static type, similar to an enum).

这篇关于使用NHibernate生成Crystal Report文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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