小编Erw*_*in1的帖子

如何在Linq查询中选择最小和最大日期值

我正在从SQL迁移到Linq,我需要一些帮助.我正在测试Linq-to-SQL和Linq-to-Entities.我想尝试两者来决定哪一个最适合我.非常感谢您的帮助.谢谢

从表中选择最小日期值的正确语法(在vb.net中,如果可能)是什么?

Dim mydata As New DataClassesDataContext
Dim myresult = From cv In mydata.T1s
                       Select cv.DATE1, cv.Date2, cv.Datex
myresult=Dump()
Run Code Online (Sandbox Code Playgroud)

我试过试过用

Select amin=cv.DATE1.Min(), amax=cv.Date1.Max(), bmin=cv.Date2.Min(), etc....
Run Code Online (Sandbox Code Playgroud)

给出了这个错误'Min' is not a member of 'Date'.

我想要获得最小值和最大值的数据如下:

IOrderedQueryable<VB$AnonymousType_0<DateTime,DateTime>> (16 items) 

Date1                   Date2
17/Oct/09 12:00:00 AM   23/Oct/09 12:00:00 AM
10/Jan/09 12:00:00 AM   15/Feb/09 12:00:00 AM
27/Mar/09 12:00:00 AM   27/Mar/09 12:00:00 AM
30/May/09 12:00:00 AM   30/May/09 12:00:00 AM
25/Jan/09 12:00:00 AM   25/Mar/09 12:00:00 AM
01/Nov/09 12:00:00 AM   01/Nov/09 12:00:00 AM
21/Feb/09 12:00:00 AM   04/Mar/09 …
Run Code Online (Sandbox Code Playgroud)

linq linq-to-sql

37
推荐指数
2
解决办法
13万
查看次数

替换JSON对象中的值

data从apicontroller返回了以下JSON对象:

> [  {"id":2,"text":"PROGRAMME","parent":null},
> {"id":3,"text":"STAGE","parent":2},
> {"id":4,"text":"INFRA","parent":2},
> {"id":5,"text":"SYSTEM","parent":3},
> {"id":6,"text":"STOCK","parent":3}, {"id":7,"text":"DPT","parent":3},
> {"id":9,"text":"EXTERNAL","parent":null}  ]
Run Code Online (Sandbox Code Playgroud)

我想,以取代"parent":null"parent":'"#"'

我已经尝试过下面的代码,但它只是替换了第一次出现的代码"parent":null.如何更换所有"parent":null条目?

<script>
     $(document).ready(function () {
         $.ajax({
             url: "http://localhost:37994/api/EPStructures2/",
             type: "Get",
             success: function (data) {
                 var old = JSON.stringify(data).replace(null, "'#'"); //convert to JSON string
                 var new = JSON.parse(old); //convert back to array
             },
             error: function (msg) { alert(msg); }
         });
     });
</script>
Run Code Online (Sandbox Code Playgroud)

谢谢,

javascript arrays json stringify

4
推荐指数
2
解决办法
5万
查看次数

自我参照关系:选择儿童和孙子女

我的ADO.Net实体数据模型下面有一个名为ABC的模型(以自引用表为模型).

ABC Properties are
----------
ParentID
Child ID

ABC Navigation Properties are
----------
ParentCategory (refers to the parent category or the 0..1 side of the relationship)
SubCategories (refers to the children or the * side of the relationship, represents the navigation property for the children)
Run Code Online (Sandbox Code Playgroud)

我想为特定的ParentID(即不是层次结构的顶部)选择子孙.我怎样才能做到这一点.有人可以提出一个例子.谢谢


我在vb中尝试了下面提出的解决方案,但它只加载了一个级别;

我在VB中这样做,所以向C#程序员道歉.

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
        Dim ctx = New links2Entities
        Dim query = From c In ctx.PBS.Include("SubCategory.SubCategory") Where (c.Parent_ID = 7)
        For Each result As …
Run Code Online (Sandbox Code Playgroud)

ado.net entity-framework entity-framework-4

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