gpt4 book ai didi

C# LINQ 错误帮助

转载 作者:太空宇宙 更新时间:2023-11-03 14:23:10 25 4
gpt4 key购买 nike

下面是 LINQ 语句的摘录,该语句抛出以下错误。有没有办法像我在下面做的那样引用 ID (ID = af.AgileFactorID)?....psf.AgileFactorID == tagSummary.ID ?预先感谢您的帮助!

select new {
ID = af.AgileFactorID,
Total = psf.Count()
};

1) 当前上下文中不存在名称 af,2) 当前上下文中不存在名称 psf

var tagCloud = from psf in tagSummary where psf.AgileFactorID == tagSummary.ID

1) 错误 62“AnonymousType#1”不包含“AgileFactorID”的定义,并且找不到接受“AnonymousType#1”类型的第一个参数的扩展方法“AgileFactorID”(您是否缺少 using 指令或汇编引用?)

2) 错误 63“System.Collections.Generic.IEnumerable”不包含“ID”的定义,并且找不到接受“System.Collections.Generic.IEnumerable”类型的第一个参数的扩展方法“ID” (您是否缺少 using 指令或程序集引用?)

这是完整的查询:

private void BindTagCloud()
{



var tagSummary = from af in db.AgileFactors
join psf in db.ProjectStoryFactors on af.AgileFactorID equals psf.AgileFactorID
join s in db.Stories on psf.StoryID equals psf.StoryID
join pim in db.ProjectIterationMembers on pim.ProjectIterationMemberID equals s.ProjectIterationMemberID
join i db.Iteration on ...
join p db.Project on ....
where p.ProjectID == proj_id &&
p.ProjectID == i.ProjectID &&
i.ProjectIterationID == pim.ProjectIterationID &&
pim.ProjectIterationMemberID == s.ProjectIterationMemberID &&
s.StoryID == psf.StoryID &&
psf.AgileFactorID == af.AgileFactorID
group af by af.Name into tagGroup

select new
{

ID = af.AgileFactorID,
Total = psf.Count()

};


var tagCloud = from psf in tagSummary
where psf.AgileFactorID == tagSummary.ID
select new
{

Name = psf.Name,
ID = psf.AgileFactionID,
Count = psf.Count(),

weight = Count / tagSummary.Total * 100

};


ListView1.DataSource = tagCloud;
ListView1.DataBind();

}

最佳答案

您的“完整查询”可能不正确,因为它有许多语法错误和缺失部分。

不过,我能重构的最好的是:

var tagSummary =
from af in db.AgileFactors
join psf in db.ProjectStoryFactors
on af.AgileFactorID equals psf.AgileFactorID
join s in db.Stories on psf.StoryID equals s.StoryID
join pim in db.ProjectIterationMembers
on s.ProjectIterationMemberID equals pim.ProjectIterationMemberID
join i in db.Iteration
on pim.ProjectIterationID equals i.ProjectIterationID
join p in db.Project on i.ProjectID equals p.ProjectID
where p.ProjectID == proj_id
group af by new { af.Name, af.AgileFactorID } into tagGroup
select new
{
ID = tagGroup.Key.AgileFactorID,
Name = tagGroup.Key.Name,
Count = tagGroup.Count()
};


var tagCloud =
from t in tagSummary
join psf in db.ProjectStoryFactors
on t.ID equals psf.AgileFactorID into psfs
let Count = psfs.Count()
let Total = tagSummary.Count()
select new
{
t.Name,
t.ID,
Count,
Weight = (double)Count / Total * 100,
};

这个查询如何为您工作?很近吗?

关于C# LINQ 错误帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4785963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com