0

I have this model and I want to write a where clause that query specific results based on and array, for example I want to show only the song that has an id in the array [1, 3, 7, 8]: I wrote the expression below but I don't know how to write the where statement:

var model = from c in _db.Categories
                from co in _db.Composers
                from k in _db.Keys
                from p in _db.Poets
                from si in _db.Singers
                from t in _db.Types
                join s in _db.Songs on
                    new
                    {
                        Catid = c.id,
                        Comid = co.id,
                        Keyid = k.id,
                        Poetid = p.id,
                        Singerid = si.id,
                        Typeid = t.id
                    }
                    equals
                    new
                    {
                        Catid = s.CategoryId,
                        Comid = s.ComposerId,
                        Keyid = s.KeymId,
                        Poetid = s.PoetId,
                        Singerid = s.SingerId,
                        Typeid = s.TypeId
                    }
                where
                      ............
                        select new SongViewModel
                        {
                            id = s.id,
                            Name = s.Name,
                            Lyric = s.Lyric,
                            Chord = s.Chord,
                            Note = s.Note,
                            Audio = s.Audio,
                            Lycho = s.Lycho,
                            Likes = s.Likes,
                            Dislikes = s.Dislikes,
                            Category = c.Name,
                            Composer = co.Name,
                            Keym = k.Name,
                            Poet = p.Name,
                            Singer = si.Name,
                            Type = t.Name
                        };
1
  • 1
    That's a very long query and your question is very short on details. Do you think you could create a short but complete example which doesn't require that many joins, or that large an entity? I'd expect there to be a short but complete example feasible in about 20 lines... Commented Jan 12, 2016 at 20:48

1 Answer 1

2

Try this:

var ids = new List<int> {1,3,7,8};

  ...
where ids.Contains(s.Id)
select
  ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.