0

如果我的词汇在以下问题上不正确,我深表歉意。

我有一个 SQL 数据库,它与该数据库中的表有多个关系。我为这个数据库创建了一个 DataContext 并创建了一个用于调用它的数据的函数存储库。

我的问题是,由于关系(多链接表)。

我是否应该创建自己的类对象来保存结果并只获取所需表的列数据,如下所示:

   public IQueryable<VM_userLogs> getUserLogsVM(Nullable<DateTime> startDate, Nullable<DateTime> endDate)
{
    if (startDate == null) {
        startDate = Convert.ToDateTime("01-01-1900");
    }

    if (endDate == null) {
        endDate = Convert.ToDateTime("01-01-2900");
    }

    IQueryable<VM_userLogs> logs = from l in ctx.tools_trt_userLogs 
                   where l.timeStamp >= startDate & l.timeStamp <= endDate 
                   select new VM_userLogs {
                            LOG_ID = l.logId,
                            NTLOGIN = l.ntLogin,
                            PRODUCT = l.productName,
                            SEGMENT = l.segmentName,
                            PRIORITY = l.priority,
                            GROUP = l.groupName,
                            ANSWER = l.answerText,
                            TIMESTAMP = l.timeStamp,
                            URL = l.url
                        };
    return logs;
}

或者我可以只从数据上下文中调用底层对象而不会对性能造成很大影响......如下所示:

    public IQueryable<tools_trt_userLogs> getUserLogs(Nullable<DateTime> startDate, Nullable<DateTime> endDate)
{
    if (startDate == null)
    {
        startDate = Convert.ToDateTime("01-01-1900");
    }

    if (endDate == null)
    {
        endDate = Convert.ToDateTime("01-01-2900");
    }

    IQueryable<tools_trt_userLogs> logs = from l in ctx.tools_trt_userLogs
                                   where l.timeStamp >= startDate & l.timeStamp <= endDate
                                   select l;
    return logs;
}
4

0 回答 0