开发者

C# LINQ Tag Cloud

开发者 https://www.devze.com 2023-02-06 13:26 出处:网络
I am trying to create a tag cloud in C# using LINQ. I have never used LINQ before, so I am getting a number of syntax errors. Could someone help me fix my code? Thanks in advance for your help!

I am trying to create a tag cloud in C# using LINQ. I have never used LINQ before, so I am getting a number of syntax errors. Could someone help me fix my code? Thanks in advance for your help!

private void BindTagCloud()
{



var tagSummary = from af in db.AgileFactors
               join psf in db.ProjectStoryFactors
               join s in db.Stories
               join pim in db.ProjectIterationMembers
               join i db.Iteration
               join p db.Project
               where p.ProjectID == proj_id 
                     p.ProjectID == i.ProjectID and
               开发者_开发技巧      i.ProjectIterationID == pim.ProjectIterationID and
                     pim.ProjectIterationMemberID == s.ProjectIterationMemberID and
                     s.StoryID == psf.StoryID and
                     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();

}


LINQ != TSQL; each and should be C#, &&; each join should specify the left and right parts (with equals) immediately, i.e.

join newAlias in newSet on existingAlias.Key equals newALias.Key

If you want to write TSQL, that is fine - just use .ExecuteQuery<T>(tsql, args)


Thanks Marc, I got rid of most of the errors by fixing the joins. There are 4 errors remaining:

select new {

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

};

1) The name af does not exist in the current context, 2) the name psf does not exist in the current context

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

1) Error 62 'AnonymousType#1' does not contain a definition for 'AgileFactorID' and no extension method 'AgileFactorID' accepting a first argument of type 'AnonymousType#1' could be found (are you missing a using directive or an assembly reference?)

2) Error 63 'System.Collections.Generic.IEnumerable' does not contain a definition for 'ID' and no extension method 'ID' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?)

0

精彩评论

暂无评论...
验证码 换一张
取 消