如何两个数据源组合成一个?组合、数据源、两个

2023-09-06 16:57:28 作者:感情,不过只是玩玩。

我有两个表,和1对象记录, 我想要从两个表中的数据为1的GridView,(两个表具有相同的字段),我不能加入,因为我需要显示所有的行

这是我的code:

  VAR的查询=从所有DB.Movies
            其中,all.IsActive
            选择新MoviesObject
            {
                PHOTOID = all.PhotoId,
                标题= all.Title,
                说明= all.ShortDescription
            };
VAR querytwo =所有在DB.movi​​eslisttwo
               其中,all.IsActive
               选择新MoviesObject
               {
                   PHOTOID = all.PhotoId,
                   标题= all.Title,
                   说明= all.ShortDescription
               ;
返回query.ToList();
 

解决方案

 返回query.Concat(query2).ToList();
 

另外,您也可以致电 .Union()跳过重复。

组合多个数据源中的数据 Power Query

i have records in two tables, and 1 object, i want to retrieve data from both tables into 1 gridview, (both tables have same fields) i can not have joins because i need to show all rows

here is my code:

var query = from all in DB.Movies
            where all.IsActive
            select new MoviesObject
            {
                PhotoId = all.PhotoId,
                Title = all.Title,
                Description = all.ShortDescription
            };
var querytwo = from all in DB.movieslisttwo
               where all.IsActive
               select new MoviesObject
               {
                   PhotoId = all.PhotoId,
                   Title = all.Title,
                   Description = all.ShortDescription
               ;
return query.ToList();

解决方案

return query.Concat(query2).ToList();

Alternatively, you can call .Union() to skip duplicates.