覆盖Rails中的默认路由(Override default routing in Rails)
我们可以覆盖Rails提供的资源的默认路由吗? 在我的应用程序中,我希望只能通过put方法访问new.html.erb。 但是,通过定义
map.resources :model
将使用get方法访问new.html.erb,我想改变它。 我可以吗?Can we override the default routing for resources provided by Rails? In my app I want new.html.erb to be accessed only by put method. But, by defining
map.resources :model
will give access with get method to new.html.erb and I want to change that. Can I?
原文:
最满意答案
当然,我可能会弄错,但它看起来像你的LINQ查询的
COUNT(*)
正在分组上运行,而不是在UserCategory
上UserCategory
。如果用
g.Count()
替换g.Count()
会发生什么?如果表没有行,
COUNT(*)
将不返回1。 只有当表中有1行或更多行并且其中一行或多行中的ProjectId
列为NULL
,COUNT(ProjectId)
才会低于COUNT(*)
。I figured it out. It would appear that because it was doing
COUNT(*)
, it would returnnull
when the project id was null, as mentioned by Jay. This would then be seen as 1 in the count, screwing up the results.Changing the count part of the select to below works nicely:
CategoryCount = g.Where(grp => grp != null).Count()
Thanks for your replies
相关问答
更多-
Linq Count and Group by(Linq Count and Group by)[2023-03-04]
context.UserProfile .Where(x=>x.CompletedSetup==1 && context.webpages_UsersInRoles.Any(u=>u.UserId == x.UserId && u.RoleId == 4)) .GroupBy(x=>new {x.UserLevel, x.StudioId) .Select(x=>new {UserLevel = x.Key.UserLevel, StudioId = x.Key.StudioId, count=x.Coun ... -
尝试这个 var test = session.Query
() .GroupBy(c => new { c.Var1, c.Var2, c.Var3 }) .Select(d=> new { var1 = d.Key.var1,var2 = d.Key.var2,var3=d.Key.var3,records = d.ToList()}) .Where(e => e.record ... -
对于具有许多关系的修改模型,请考虑对原始查询进行以下修改: var top5jobfunctions = JobSearchResults.SelectMany(j => j.SearchString.Select(s => new {j,s})) .Where(j => (j.s != null)) .GroupBy(j => new { j.s.JobFunction.JobFunctionId, j.s.JobFunctio ...
-
您按多列分组: from table in context.table group new{table.UserID,table.Date} by new{table.ID,table.Name} into grp orderby grp.Key.ID descending select new { ID = grp.Key.ID, Date=grp.FirstOrDefault().Date, Name=grp.Key.Name, Users = grp.Select(e= ...
-
只需使用Count方法: from buildinguser in db.GetTable
() join building in db.GetTable () on buildinguser.ID_BUILDING equals building.ID join user in db.GetTable () on buildinguser.ID_USER equals user.ID group building by building.NAME in ... -
尝试以下操作: (from c in AllContracts group c by new {c.StatusId, c.StatusDescription} into g select new { StatusId = g.Key.StatusId, StatusDescription = g.Key.StatusDescription, CountOf = g.Count() }).OrderBy(item => item.StatusId) Try the followin ...
-
Linq集团由伯爵和伯爵组成(Linq group by and take the count)[2022-03-03]
根据您的要求 每个id应仅包含在一个状态下,并且应根据每个状态更新的最新日期进行 首先需要按Id分组,从每个分组中获取具有最新日期的元素,然后按Status对结果进行分组: var query = from e in (from e in this.logRepository.GetQuery(null) group e by e.Id into g select g.OrderByDescending(e => e.Date).First ... -
你很近。 试试以下 var names= db.User.GroupBy(fu => fu.Name) .Select(g => new { Name=g.Key, Count = g.Count() }); You are very close. Try following var names= db.User.GroupBy(fu => fu.Name) .Select(g => new { Name=g.Key, Count = g.Count ...
-
当然,我可能会弄错,但它看起来像你的LINQ查询的COUNT(*)正在分组上运行,而不是在UserCategory上UserCategory 。 如果用g.Count()替换g.Count()会发生什么? 如果表没有行, COUNT(*)将不返回1。 只有当表中有1行或更多行并且其中一行或多行中的ProjectId列为NULL , COUNT(ProjectId)才会低于COUNT(*) 。 I figured it out. It would appear that because it was doin ...
-
鉴于以下数据: Dim table = { New With { .Name = "A", .Consumed = "Flavor 1" }, New With { .Name = "B", .Consumed = "Flavor 2" }, New With { .Name = "C", .Consumed = "Flavor 1" }, New With { .Name = "C", .Consumed = "Flavor 3" }, New With { ...