0

LINQ を使用して asp mvc でサービス層の実装に取り​​組んでいます。たとえば、Stackoverflow のようなユーザー、投稿、投票があります。各ユーザーは、賛成票と反対票から得た評判を持っています。

この投票テーブルには次の属性があります: id 、postTypeId、voteTypeId、creationDate 、VoterId

この Post テーブルには次の属性があります: id、userId ....

および User テーブルには id が含まれます

賛成票ごとに 2 点が与えられ、反対票ごとに 1 点が減点されます

評判の変化を表示するには、Linq でクエリを作成する方法が必要です。

これらは私が使用する属性です。

var jointable = from vote in _dataContext.Votes
    join post in _dataContext.Posts on vote.PostId equals post.Id
    where vote.VoterId== id
    select new
    {  
        vote.Id,
        vote.CreationDate,
        vote.PostId,
        vote.VoteTypeId,
        post.PostTypeId,
        post.Title,
        post.IsAnonymous 
    };    

この後、誰かがそれらの属性を照会してオブジェクトとして返すのを手伝ってくれませんか??

4

1 に答える 1

0

あなたはすでに持っているものからそれほど離れていません。日付範囲の条件が必要なだけです。

var startDate = ...; // assume this will be selected from the UI
// assuming we are working with UTC (if you aren't, you should be)
startDate = startDate.ToUniversalTime();
var endDate = startDate.AddHours(24); // include full 24 hour day
var jointable = from vote in _dataContext.Votes
    join post in _dataContext.Posts on vote.PostId equals post.Id
    where vote.VoterId == id && vote.CreationDate >= startDate && vote.CreationDate < endDate
    select new
    {  
        vote.Id,
        vote.CreationDate,
        vote.PostId,
        vote.VoteTypeId,
        post.PostTypeId,
        post.Title,
        post.IsAnonymous 
    }; 
于 2014-01-12T18:11:49.667 に答える