如何将valyues从存储过程重新分配到类 [英] how to assign valyues retuen from store procedure to class

查看:80
本文介绍了如何将valyues从存储过程重新分配到类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii,



我有一个名为tblDrivingRegistartion的表,我创建了一个类DrivingIDgistration,它具有相同列的属性..



我正在做以下事情



Hii ,

I have a table named tblDrivingRegistartion and i have created a class DrivingRegistration which has properties of same columns ..

I am doing followinf things

public static DrivingRegistration GetDrivingRegistrationDetailsByEmployeeId(int employeeId)
        {
            DataClasses1DataContext _db = new DataClasses1DataContext();
            ISingleResult<usp_GetDrivingRegistrationDetailsByEmployeeIdResult> result = _db.usp_GetDrivingRegistrationDetailsByEmployeeId(employeeId);

        }





但是没有得到我如何从rsult和returen对象的类注册属性驱动注册类



but not get how i assgin value to class properties from rsult and returen object of drivingregistration class

推荐答案

试试这样



Try like this

public static DrivingRegistration GetDrivingRegistrationDetailsByEmployeeId(int employeeId)
       {
           DataClasses1DataContext _db = new DataClasses1DataContext();
           ISingleResult<usp_GetDrivingRegistrationDetailsByEmployeeIdResult> result = _db.usp_GetDrivingRegistrationDetailsByEmployeeId(employeeId);

           // you can map the <usp_GetDrivingRegistrationDetailsByEmployeeIdResult> properties to the
           //<DrivingRegistration> properties as

           DrivingRegistration objdriving = new DrivingRegistration();
           if (result != null)
           {
               var temp = result.FirstOrDefault();
               if (temp != null) { }
               objdriving.PropertyName = temp.PropertyName; // map your properties
               objdriving.ColumnName1 = temp.ColumnName1; // map your properties
           }


           return objdriving;

       }


您可以使用 ReturnValue



类似



You can make the ISingleResult to return the type of the Entity/POCO class using ReturnValue

Something like

[Function(Name = "usp", IsComposable = false)]
public ISingleResult<DrivingRegistration > GetDALDrivingRegistrationDetailsByEmployeeId()
{
    IExecuteResult objResult =
      this.ExecuteMethodCall(this,(MethodInfo)(MethodInfo.GetCurrentMethod()));

    ISingleResult<DrivingRegistration> objresults =
        (ISingleResult<DrivingRegistration>) objResult.ReturnValue;
    return objresults;
}



从DbContext调用此方法

参考此文



使用存储过程的六个简单步骤LINQ [ ^ ]



还有一个参考



映射存储CP链接的实体类部分的过程

LINQ to SQL:高级概念和功能 [ ^ ]


这篇关于如何将valyues从存储过程重新分配到类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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