Create temp table with Entity Framework

一笑奈何 提交于 2019-12-10 14:17:29

问题


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?

Thanks in advance.

André


回答1:


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.

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>();

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



来源:https://stackoverflow.com/questions/17231943/create-temp-table-with-entity-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!