Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用Linq查询C从帮助器类属性检索数据_C#_Linq - Fatal编程技术网

C# 如何使用Linq查询C从帮助器类属性检索数据

C# 如何使用Linq查询C从帮助器类属性检索数据,c#,linq,C#,Linq,我想从CPayment检索数据列表,但在编写linq查询时,会加载CPaymentModel类属性,但不会加载TransactionHelper类属性,因此无法查看 如何访问助手类属性或如何获取助手类和非助手类属性的列表??如何解决这个问题 我的模型类代码是 控制器代码为: 索引页KendoUI网格代码: 我的输出是: [单击]如果要创建事务助手的新对象,请使用此方法。在这里,我创建了一个新对象,并使用初始值设定项语法来设置属性 var session = SessionManager.GetC

我想从CPayment检索数据列表,但在编写linq查询时,会加载CPaymentModel类属性,但不会加载TransactionHelper类属性,因此无法查看

如何访问助手类属性或如何获取助手类和非助手类属性的列表??如何解决这个问题

我的模型类代码是

控制器代码为:

索引页KendoUI网格代码:

我的输出是:
[单击]

如果要创建事务助手的新对象,请使用此方法。在这里,我创建了一个新对象,并使用初始值设定项语法来设置属性

var session = SessionManager.GetCurrentSession();

var data2 = session.Query<CPayment>().Select(row => new CPaymentModel()
{
    CardNo = row.CardNo,
    Product = row.ProductDetails.Product,
    Subproduct = row.ProductDetails.Subproduct,
    FileDate = row.FileDate,
    Transaction = new TransactionHelper
    {
        TransCode = row.Transaction.TransCode,
        TransDate = row.Transaction.TransDate
    }
}).ToList<CPaymentModel>();
var list = data2.ToDataSourceResult(dsRequest);
这是一个完全有效的结构。当你不能用初始化器做所有事情时,它会很有用。

试试这个

var session = SessionManager.GetCurrentSession();

var data2 = session.Query<CPayment>().Select(row => new CPaymentModel()
{
    CardNo = row.CardNo,
    Product = row.ProductDetails.Product,
    Subproduct = row.ProductDetails.Subproduct,
    FileDate = row.FileDate,
    Transaction =new TransactionHelper()
    {
        TransCode = row.Transaction.TransCode;
        TransDate = row.Transaction.TransDate
    }
}).ToList<CPaymentModel>();
var list = data2.ToDataSourceResult(dsRequest);

可能调用包含方法,并将path to Transaction属性作为参数,指示EF应使用所有属性加载该方法

var session = SessionManager.GetCurrentSession();

 var data2 = session.Query<CPayment>().**Include("CPayment.Transaction").**Select(row => new CPaymentModel()
 {
        CardNo = row.CardNo,
        Product = row.ProductDetails.Product,
        Subproduct = row.ProductDetails.Subproduct,
        FileDate = row.FileDate,
        Transaction =row.Transaction
   }).ToList<CPaymentModel>();
var list = data2.ToDataSourceResult(dsRequest);

从您的示例来看,不清楚在何处以及如何存储数据。这是一个数据库吗?您是否也将TransactionHelper存储在那里?您不能访问ar视图的属性是什么意思?它们是否包含空值?或者是整行事务为空?TransactionHelper是否在CPaymentModel中声明?或者您只是没有正确格式化代码?那么,您的CPayment类中是否有CPaymentModel的列表?只需更改为索引代码Kendo UI:@Html.Kendo.Grid.NamePaymentInfo.Columnscol=>{col.Boundc=>c.CardNo;col.Boundc=>c.FileDate;col.Boundc=>c.TransCode;col.Boundc=>c.TransDate;}.DataSourcedataSource=>dataSource.Ajax.readreadread=>read.ActionGetPersons,DataBinder
var session = SessionManager.GetCurrentSession();

var data2 = session.Query<CPayment>().Select(row => new CPaymentModel()
{
    CardNo = row.CardNo,
    Product = row.ProductDetails.Product,
    Subproduct = row.ProductDetails.Subproduct,
    FileDate = row.FileDate,
    Transaction = new TransactionHelper
    {
        TransCode = row.Transaction.TransCode,
        TransDate = row.Transaction.TransDate
    }
}).ToList<CPaymentModel>();
var list = data2.ToDataSourceResult(dsRequest);
row =>
{
    CPaymentModel cpModel = new CPaymentModel()
    {
        CardNo = row.CardNo,
        Product = row.ProductDetails.Product,
        Subproduct = row.ProductDetails.Subproduct,
        FileDate = row.FileDate,
        Transaction = new TransactionHelper()
    };
    cpModel.Transaction = new Transaction();
    cpModel.Transaction.TransCode = row.Transaction.TransCode;
    cpModel.Transaction.TransDate = row.Transaction.TransDate;

    return cpModel;
}
var session = SessionManager.GetCurrentSession();

var data2 = session.Query<CPayment>().Select(row => new CPaymentModel()
{
    CardNo = row.CardNo,
    Product = row.ProductDetails.Product,
    Subproduct = row.ProductDetails.Subproduct,
    FileDate = row.FileDate,
    Transaction =new TransactionHelper()
    {
        TransCode = row.Transaction.TransCode;
        TransDate = row.Transaction.TransDate
    }
}).ToList<CPaymentModel>();
var list = data2.ToDataSourceResult(dsRequest);
var session = SessionManager.GetCurrentSession();

 var data2 = session.Query<CPayment>().**Include("CPayment.Transaction").**Select(row => new CPaymentModel()
 {
        CardNo = row.CardNo,
        Product = row.ProductDetails.Product,
        Subproduct = row.ProductDetails.Subproduct,
        FileDate = row.FileDate,
        Transaction =row.Transaction
   }).ToList<CPaymentModel>();
var list = data2.ToDataSourceResult(dsRequest);