使用实体框架创建临时表 [英] Create temp table with Entity Framework

查看:115
本文介绍了使用实体框架创建临时表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过使用实体框架在sql server中创建一个临时表。有什么办法可以做到吗?如果我可以创建一个临时表,我的下一个问题是我如何阅读?

I want to create a temp table in sql server by using Entity Framework. Is there any way I can do this? If I can create a temp table, my next question is, how I can read it?

提前感谢。

André

推荐答案

好的,所以你不喜欢存储过程路由....也不要诚实,但这是我能想到的最快的方式。

Ok, so you don't like the stored procedures route....nor do I to be honest, but it's the quickest way I could think of doing it.

根据这一点,我不知道在EDM中创建临时表的任何简单的方法,所以我的接下来的建议是创建本地对象,它模拟你想创建的临时表。临时名称显然表示您不希望他们无限期地生活在数据库上,因此在内存对象中使用的优点是可以比对数据库进行多次调用更加可控(取决于您的延迟)。

Based on that, I don't know of any easy way in EDM to create temp tables so my next suggestion would be to create local objects, which mimic the temporary table you wish to create. The name temporary obviously indicates you don't want them to live on the database indefinitely, so using in memory objects has the benefit of being much more controllable and (depending on your latency) quicker than making multiple calls to a database.

public class MyTempTable
{
    public string ID { get; set; }
    public string Column1 { get; set; }
    // your other columns here
}

List<MyTempTable> tempTable = new List<MyTempTable>();

一旦你创建了对象列表,你可以基本上做任何你通常在使用Linq的数据库表。

Once you've created your list of objects you can do basically anything you'd normally do on the database table using Linq.

这篇关于使用实体框架创建临时表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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