小编Ron*_*ald的帖子

使用Entity Framework选择多个列

也许一个简单的问题,但无法轻易找到它原谅我=)我尝试选择多个列.我使用的声明是:

var dataset2 = from recordset in entities.processlists 
               where recordset.ProcessName == processname 
               select recordset.ServerName, recordset.ProcessID, recordset.Username;
Run Code Online (Sandbox Code Playgroud)

显然,这甚至都没有编译.什么是正确的语法?我也试过基于方法,甚至强硬这个语法似乎是正确的,当访问它时抛出'无法强制转换类型'匿名类型'来键入'AIM.PInfo'.LINQ to Entities仅支持转换EDM原语或枚举类型.例外.

有任何想法吗?

var dataset = entities.processlists
             .Where(x => x.environmentID == environmentid && x.ProcessName == processname && x.RemoteIP == remoteip && x.CommandLine == commandlinepart)
             .Select(x => new { x.ServerName, x.ProcessID, x.Username })
             .Cast<PInfo>().ToList();
Run Code Online (Sandbox Code Playgroud)

.net c# entity-framework

50
推荐指数
4
解决办法
20万
查看次数

从MVC控制器获取FileStream到客户端

我使用下面的代码将文件流放入由 MVC 控制器返回的响应消息中。但是如何在客户端获取流?任何评论高度赞赏!谢谢!

服务器:

string filename = @"c:\test.zip";

FileStream fs = new FileStream(filename, FileMode.Open);

HttpResponseMessage response = new HttpResponseMessage();

response.Content = new StreamContent(fs);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

return response;
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc asp.net-mvc-4

3
推荐指数
1
解决办法
2万
查看次数

预先变量变量总是必要的吗?

也许有点愚蠢的问题,但是c#的语法方式是什么?如果我从字典中检索值并且我不确定它们是否存在,我是否需要预先确定它们,所以如果它们存在,我可以在以后使用m?

示例(稍后我需要在代码中使用'string bla'):

string bla = null;
if (myDictionary.ContainsKey("unknownKey"))
{
    bla = myDictionary["unknownKey"];
}

if (bla != null) {  etc etc etc }
Run Code Online (Sandbox Code Playgroud)

我必须检查字典中的很多项目,还有一些更复杂的类型,所以这将是一个相当大的预先声明...

但我认为在这种情况下问问题是回答它... Cheerz!

c# dictionary scope

3
推荐指数
2
解决办法
133
查看次数

返回多个文件以从 asp.net 下载

谁知道怎么做?我有一个循环,并在该循环中建立了一个列表。我希望每个列表都保存为具有不同文件名(废话)的不同文件。我为此使用 HttpContext.Current.Response。单个文件工作正常,但是,我无法循环它。我在第二次迭代时收到的错误是“发送 HTTP 标头后服务器无法清除标头”。我的代码有点像下面。当然重要的是 // response to user 所评论的部分。任何评论高度赞赏!

干杯,罗纳德

        foreach (GridViewRow dr in GridView1.Rows)
        {
            // find the check box in the row
            System.Web.UI.WebControls.CheckBox cb = (System.Web.UI.WebControls.CheckBox)dr.FindControl("chkbx_selected");

            // see if it's checked
            if (cb != null && cb.Checked)
            {
                // get the cell
                DataControlFieldCell Cell = GetCellByName(dr, "GUID");
                string guid = new Guid(Cell.Text);

                // get the record filtered on the GUID
                var result_json = call_WEBAPI(guid);

                // result_json contains serialized List<string>
                List<string> result = JsonConvert.DeserializeObject<List<string>>(result_json);

                // response to user
                string …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc-4

0
推荐指数
1
解决办法
1万
查看次数