English 中文(简体)
与主要项目相比,按分项顺序排列
原标题:Linq orderby sum of sublist item compared to mainlist item

我曾提出一个问题,但未能找到解决办法。 简化问题:我有两张桌椅,一米用LinQ到Q。 这两张表格是课程表,课程表包括课程表和总课程表,课程表包括课程表、数额和课程表。 课程表和课程表之间的关系很大。

现在,我需要帮助的是Linaq query/Lambda表达方式,以划分课程表和课程内容(如果可行)。 我想,在全部免费点数(从课程大纲的每门课程升级;课程表——课程表上签字)之后,对课程表进行分类。 我想将课程内容按课程设置的免费地点分类(CourseType)。 TotalSpots - CourseInstance.Amount 常驻代表

I can t get my head around how to solve this. I ve looked at simlar questions and issue and this is what I ve made so far, just to give a basic idea:

Edit:我是迄今为止将正确确定课程表的。 我不敢确定我如何能够将课程内容列入分类(CourseType.CourseInstance)。 我猜测,如果我把名单改成名单,除非有人对此有很好的解决办法,那么我就不得不在守则中稍后这样做。 我可以按照Arion所建议的那样做,为什么我赞扬他的回答。

var result= (
        from c in _db.CourseType
        orderby ((c.TotalSpots * c.CourseInstance.Count) - c.CourseInstance.Sum(
                                ci => (ci.AmountSignUp ?? 0))) descending
        select c
     );
最佳回答

我并不真正相信你想要什么。 但是,你希望通过<条码>c 发出这样的声音。 总仓库 - 阁下: 但这还不够?

var result=(
    from ct in db.CourseType
    join ci in db.CourseInstance
        on ct.SomeCourseTypeKey equals ci.SomeCourseInstanceKey
    orderby c.TotalSpots - ci.AmountSignedUp
    select new {ci,ct}
    );

db是林克数据环境。

或如果<条码>c.TotalSpots和ci.Amount 签名Upnullable 那么,

var result=(
        from ct in db.CourseType
        join ci in db.CourseInstance
            on ct.SomeCourseTypeKey equals ci.SomeCourseInstanceKey
        orderby (c.TotalSpots??0) - (ci.AmountSignedUp??0)
        select new {ci,ct}
        );

我仍然不相信你想要,但我还是不希望。 你可以这样做:

var result=(
    from ct in db.CourseType
    orderby ct.TotalSpots
    select new 
    {
        ci,
        CourseInstances=(
            from ci in db.CourseInstance
            where ct.SomeCourseTypeKey == ci.SomeCourseInstanceKey
            orderby ct.TotalSpots- ci.AmountSignedUp
            select ci
        )
    }
    );
问题回答

暂无回答




相关问题
IEnumerable to array of parameter

Using linq? and XML is there a way to convert this IEnumerable to a string array of the value parameter? List<string> idList = new List<string>(); foreach (XElement idElement in word....

linq query for tag system - search for multiple tags

I have two tables, Tags(tagid, postid, tagname) and posts(postid, name, ...) now i want to make a query that returns me all posts that have a generic amount of tags. like: i want all posts that have ...

Linq operations against a List of Hashtables?

I m working with a set of legacy DAO code that returns an IList, where each Hashtable represents the row of a dynamically executed SQL query. For example, the List might contain the following records/...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

How to filter duplicate list items

i have list of items IList with data that looks list this: GenId TestMode 1 0 1 1 3 0 3 1 4 NULL 2 NULL i want to remove the index ...

C# Grouping/Sorting a Generic List<> using LINQ

Im looking to group and sort a Generic List<>. I have a list of objects representing files and each of these objects has a FileName, FileType and FileDate property. FileType is defined as an ...

热门标签