从类中返回一组对象

时间:2013-03-14 16:39:15

标签: c#-4.0 entity-framework-4

我有一个方法可以向EF表添加一个新项,然后查询该表以返回该表的一个子集。它需要向调用者返回一组“行”,每行都是一组列。我不知道该怎么做。我有一些代码,但我认为这是错误的。我不想返回一行,我想返回零行或多行。我不确定使用什么DataType ... [qryCurrentTSApproval是一个EF对象,指SS中的一个小视图。 tblTimesheetEventlog也是一个EF对象,指的是基础表]

想法?

    private qryCurrentTSApproval LogApprovalEvents(int TSID, int EventType)
    {
        using (CPASEntities ctx = new CPASEntities())
        {
            tblTimesheetEventLog el = new tblTimesheetEventLog();
            el.TSID = TSID;
            el.TSEventType = EventType;
            el.TSEUserName = (string)Session["strShortUserName"];
            el.TSEventDateTime = DateTime.Now;
            ctx.tblTimesheetEventLogs.AddObject(el);
            ctx.AcceptAllChanges();

            var e = (from x in ctx.qryCurrentTSApprovals
                     where x.TSID == TSID
                     select x);
            return (qryCurrentTSApproval)e;
        }
    }

1 个答案:

答案 0 :(得分:0)

将方法返回类型更改为qryCurrentTSApproval

的集合
private List<qryCurrentTSApproval> LogApprovalEvents(int TSID, int EventType)
{
   using (CPASEntities ctx = new CPASEntities())
   {
     //  some other existing code here 

     var itemList = (from x in ctx.qryCurrentTSApprovals
                                     where x.TSID == TSID
                                                  select x).ToList();
     return itemList;
   }
}
相关问题