首页 \ 问答 \ 如何在Linq lambda表达式中选择'新'?(How to 'select new' inside Linq lambda expression?)

如何在Linq lambda表达式中选择'新'?(How to 'select new' inside Linq lambda expression?)

我如何在一个声明中做到这一点,而不是在两个分手?

 var newpeople= _rep.GetPeople().Where(p=>p.personID).Select(new KindoFPerson...id=p.id etc)

How do i do this in one statement vs breaking up in two?

 var newpeople= _rep.GetPeople().Where(p=>p.personID).Select(new KindoFPerson...id=p.id etc)

原文:https://stackoverflow.com/questions/900264
更新时间:2019-07-05 04:25

最满意答案

var newpeople= _rep.GetPeople().Where(p=>p.personID)
    .Select(p => new KindoFPerson...id=p.id etc)

注意新的“ p => ”。


var newpeople= _rep.GetPeople().Where(p=>p.personID)
    .Select(p => new KindoFPerson...id=p.id etc)

Note the new "p =>".

2009-05-22

相关问答

更多

LINQ选择项的Lambda表达式(Lambda Expression for LINQ Select Items)

查看C#编译器生成的表达式并尝试复制它的作用: Expression<Func<Project, object>> lambda = (Project p) => (object)new {id=p.Id, title=p.Title,pc=p.PostalCode }; 我希望这段代码可以编译。 如果没有,你肯定能够解决它。 然后,查看lambda变量的内容。 注意,转换为object只是为了进行编译。 你不需要/想要那是生产。 Look at the expression the

将linq查询转换为lambda表达式(Convert linq query to lambda expression)

_dbNavigation.Table1 .Join(_dbNavigation.Table2, t1 => t1.PropName, t2 => t2.PropName, (t1, t2) => new { t1, t2 }) .Where(x => x.t1.IsDeleted == false && x.t2.UserName == "REX") .Select(x => x.t2); _dbNavigatio

Linq to Lambda Expression c#(Linq to Lambda Expression c#)

finaldatelist.GroupBy(x => new { x.RoomID, x.RateGroupID }); finaldatelist.GroupBy(x => new { x.RoomID, x.RateGroupID });

如何将此SQL查询转换为LINQ或Lambda表达式?(How to convert this SQL query to LINQ or Lambda expression?)

这可能会做你想要的: Layout .Where(x => Position .Where(y => y.Code == "TopMenu") .Select(y => SqlClient.SqlMethods.Like(x.PositionID, "%" + y.ID.ToString() + "%") ).Count() > 0 ).Join( Category, x => x.CategoryI

如何在lambda表达式中“让”?(How to “let” in lambda expression?)

所以,你可以使用扩展方法的语法,这会涉及一个比你当前使用的lambda表达式更多的语法。 没有let ,你只需使用多行lambda并声明一个变量: var results = Stores.Where(store => { var averagePrice = store.Sales.Average(s => s.Price); return averagePrice > 250 && averagePrice < 500; }); 请注意,我更改了平均价格比较,因为您的结果永 ...

Linq lambda表达多对多表选择(Linq lambda expression many to many table select)

你可以这样做: var query = from lo in this._mediaBugEntityDB.LotteryOffers where lo.lotteryOfferId == lotteryOfferId from ld in lo.LotteryDrawDates group ld by ld.Lottery into grp select grp.Key; 我在查询语法中这样做,因

重构此Lambda表达式(Refactor this Lambda Expression)

_attributeGroups = attributeGroups.Select(attributeGroupRowModel => { var wt = workTypes.First(x => x.Id == attributeGroupRowModel.WorkTypeId); return new AttributeGroupRowModel() { Name = attributeGroupRowModel.Name,

在linq或lambda表达式中执行查询SQL?(as performed query SQL in linq or lambda expression?)

这是提示: var result = ents.T1 .Where(x => list.Contains(x.Id)) .GroupBy(x => new { Id2 = x.T2.Id, Id3 = x.T3.Id, ... // etc group fields ...

相关文章

更多

最新问答

更多
  • 使用javascript为用户延迟加载内容的更好方法是什么?(What is a better way to lazy load content for users with javascript?)
  • 如何修复无法将类型的值...转换为预期的参数类型inout _(How to fix Cannot convert value of type … to expected argument type inout _)
  • 从哪里开始解析JSON?(Where to start with parsing JSON?)
  • Mail.php不适用于.htaccess(Mail.php doesn't work with .htaccess)
  • 使用htaccess设置子域(Setting subdomains using htaccess)
  • mod_pagespeed和java应用服务器(mod_pagespeed and java app servers)
  • Win32:如何崩溃?(Win32: How to crash?)
  • FFmpeg中RGB到YUV转换的错误(Error in RGB to YUV conversion in FFmpeg)
  • 如何在Android中首次打开应用时创建弹出窗口?(How to create pop-up when first open app in Android?)
  • 通过动态传递表名和列名来反转COLUMN DATA(Reversing COLUMN DATA by dynamically passing table name and Column Name)
  • 如何计算C#中ICollection中有多少元素?(How can I count how many elements are in an ICollection in C#)
  • 从pg-promise查询中获得结果(get result out of a pg-promise query)
  • 使用管理器注册一个类,然后调用子类重写方法(Register a class with a manager, then call the sub classes overridden methods)
  • 传递&在查询字符串中(Passing & in query string)
  • 谷歌浏览器打印预览不会第一次加载页面(google chrome print preview does not load the page the first time)
  • FsLexYacc:Tests / MiniProject“在.fsproj中导入错误”(FsLexYacc : Tests/MiniProject “incorrect Import in .fsproj”)
  • 创建一个模型方法,计算用户的帖子并在rspec(Rails)中测试?(Create a model method that counts a user's posts and test in rspec (Rails)?)
  • 记录线程的奇怪行为(Strange behaviour of logging thread)
  • 移动数组中的索引(Moving indices in an array)
  • MVC 5 - > MVC 5.1迁移。(MVC 5 -> MVC 5.1 Migration. Intellisense issues)
  • 使用函数在z3中创建列表(Creating List in z3 using function)
  • 如何进行html随机重定向(How to make a html random redirect)
  • 角度js:使用角度过滤器分割日期,月份和时间(Angular js: spliting date,month and time using angular filter)
  • 将所有模块导入一个文件夹,并按其属性之一使用它们(Import all modules in one folder and use them by one of its attributes)
  • 只需要在git的当前分支上获得合并列表(Just get list of merge happened on my current branch in git)
  • React-Native导入库并在多个组件中可用(React-Native import a library and make available in multiple components)
  • 如何使用jQuery为固定(偏移)位置设置div动画?(How to animate div for a fixed (offset) position using jQuery?)
  • operator ==和vector confusion(operator== and vector confusion)
  • 如何获取所选图像映射alt值?(How to get selected image map alt value?)
  • 在角度,如何使用取消用户事件的美元间隔,如页面更改?(In angular, how to use cancel an $interval on user events, like page change?)