首先,我是Linq的新手.
我有一个名为的对象列表,Lba它们具有不同的属性要进行分组.我的对象属性是:
int aId,
int bId,
int max,
int min,
CustomObject1? Co1,
CustomObject2? Co2,
CustomObject3? Co3
Run Code Online (Sandbox Code Playgroud)
我想将对象分组到具有以下属性的新对象LbaGroup中
int aId,
int bId,
int max,
int min,
IList<CustomObject1> Co1,
IList<CustomObject2> Co2,
IList<CustomObject3> Co3
Run Code Online (Sandbox Code Playgroud)
我使用以下查询对对象进行分组,但它返回List>
var query = myLbaList
.GroupBy(a => new {a.aId, a.bId, a.max, a.min})
.Select(a => a.ToList())
.ToList();
Run Code Online (Sandbox Code Playgroud)
我能够用2个foreach循环构建我的新对象,但我想知道是否有直接的方法来实现Linq.
谢谢.
编辑:我的循环看起来像:
foreach(List<Lba> LbaList in query){
LbaGroup myNewObject = new LbaGroup{
Co1 = new List<CustomObject1>(),
Co2 = new List<CustomObject2>(),
Co3 …Run Code Online (Sandbox Code Playgroud) 我有一个包含标题和值的表格。
对于不同的标题,我想检索所有非空值,除非该标题仅具有 NULL 值。
我的表格示例如下所示:
Title Value
---------------
ex1 8
ex1 9
ex1 NULL
ex2 8
ex2 NULL
ex3 NULL
Run Code Online (Sandbox Code Playgroud)
在这个例子中,我希望我想要的输出如下所示:
Libelle TPO_code
--------------------
ex1 8
ex1 9
ex2 8
ex3 NULL
Run Code Online (Sandbox Code Playgroud)
我可以通过以下请求实现检索除 NULL 值之外的所有值,但由于标题只有 NULL 值的情况而被阻止:
select distinct Title, Value
from mytable
where Value is not null
Run Code Online (Sandbox Code Playgroud) 我正在通过 Angular 6 从 Web API 检索数据。
我创建了一个带有 fetch 函数的服务,该函数在组件构造函数中调用,该函数将在同一页面上多次实例化。
我的问题是每次实例化我的组件时都会调用该服务。
例如我的代码如下:
服务 :
import { Injectable } from '@angular/core';
import { Article } from '../../Classes/article'
import { Observable } from 'rxjs';
import { MessageService } from '../../Services/message/message.service'
import { HttpClient } from '@angular/common/http'
@Injectable({
providedIn: 'root'
})
export class ArticleService {
Values: Observable<Article[]> ;
constructor(private messageService: MessageService, private http : HttpClient)
{
this.buildArticles()
}
private articlesUrl = 'http://localhost:63138/v/Article'
private buildArticles(): void {
this.Values = this.http.get<Article[]>(this.articlesUrl)
}
getArticles() : Observable<Article[]> …Run Code Online (Sandbox Code Playgroud) 我想做一个选择请求,执行第一个选择,然后使用该选择执行第二个选择。
我使用临时表制作了第一个版本,但我想知道是否有办法在没有临时表的情况下做到这一点
我的临时表代码如下:
select dvd_name, book_name , count(*) nb
into #t
from usr
inner join book on usr_book_id = book_id
inner join dvd on dvd_id = usr_dvd_id
group by dvd_name, book_name
having count(*) > 1
select top 10 usr_smthg, #t.book_name,dvd_name
from #t
inner join book b on b.book_name = #t.book_name
inner join usr on usr_book_id = book_id
Run Code Online (Sandbox Code Playgroud)