小编yDe*_*per的帖子

Linq-To-Entities使用方法选择新对象

我尝试在我的应用程序中多次使用相同的选择查询.例如,我有这个select语句:

 _db.tbl_itembundlecontents
                    .Select(z => new SingleItemDTO
                    {
                        amount = z.amount,
                        id = z.id,
                        position = z.position,
                        contentType = new BasicMaterialDTO
                        {
                            id = z.tbl_items.id,
                            img = z.tbl_items.tbl_material.img,
                            name = z.tbl_items.tbl_material.name,
                            namekey = z.tbl_items.tbl_material.namekey,
                            info = z.tbl_items.tbl_material.info,
                            weight = z.tbl_items.tbl_material.weight
                        }
                    });
Run Code Online (Sandbox Code Playgroud)

但我也有这个:

 _db.tbl_itembundle
                .Where(x => x.type == 2)
                .Select(y => new ItemBundleDTO
                {
                    name = y.name,
                    namekey = y.namekey.
                    contents = y.tbl_itembundlecontents
                    .Select(z => new SingleItemDTO
                    {
                        amount = z.amount,
                        id = z.id,
                        position = z.position,
                        contentType = new BasicMaterialDTO …
Run Code Online (Sandbox Code Playgroud)

c# linq asp.net-mvc linq-to-entities entity-framework

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