2

I have an AlbumArtist class (which is my EF Entity):

public class AlbumArtist : IEquatable<AlbumArtist>
{
    public int Id { get; set; }

    public string Title { get; set; }

    public virtual List<Album> Albums { get; set; }

    public bool Equals(AlbumArtist albumArtist)
    {
        return Title.Equals(albumArtist.Title);
    }

    public override int GetHashCode()
    {
        return Title.GetHashCode();
    }
}

And an Album class (which is my EF Entity too):

public class Album : IEquatable<Album>
{
    public int Id { get; set; }

    public string Title { get; set; }

    public virtual List<AlbumArtist> AlbumArtists { get; set; }

    public bool Equals(Album album)
    {
        return Title.Equals(album.Title);
    }

    public override int GetHashCode()
    {
        return Title.GetHashCode();
    }
}

So, as you see, I have many-to-many relationship.

I create one list, populate it, than save it with DbContext, then I create and populate the second list. And then I try to merge that two lists (one from DbContext, second from the local variable) and save the result to DbContext as well (insert new entities and update existing).

I have the following data in my two lists:

--Infected Mushroom
----Classical Mushroom
----Converting Vegetarians
...



--Infected Mushroom
----The Gathering ‎
----Converting Vegetarians
--Skazi
...

And I try to get the following data:

--Infected Mushroom
----Classical Mushroom
----The Gathering ‎
----Converting Vegetarians
--Skazi
...

Please help me to write some LINQ query to achieve my goal.

Thanks!


Jquery code doesn't work in Chrome

I really don't understand why this snippet works in all browsers but chrome :S

    $(".tab1, .tab2, .tab3").css({"height":newHeight}).getNiceScroll().resize();

http://radio.idev.ge

EDIT

This looks like a jquery bug with css() for chrome, I changed css() to animate() and it works fine now.

I'm gonna submit bug report.

4

2 に答える 2

2

関数の助けを借りてLINQで可能SelectManyです。

あなたはここの例を見つけることができますSelectMany

于 2013-09-05T11:34:51.900 に答える
0

LINQ 演算子Joinとを使用できますUnion。これを実証するために、問題を文字列のグループの 2 つのリストに単純化しました。

var list1 = new[] {
    Tuple.Create("Infected Mushroom", "Classical Mushroom"),
    Tuple.Create("Infected Mushroom", "Converting Vegetarians"),
    Tuple.Create("Skazi", "Animal")
}
.GroupBy(t => t.Item1, t => t.Item2);
var list2 = new[] {
    Tuple.Create("Infected Mushroom", "The Gathering"),
    Tuple.Create("Skazi", "Animal")
}
.GroupBy(t => t.Item1, t => t.Item2);

各リストの各項目は でIGroupingKeyはアーティストで、 の要素はIGroupingアルバムです。

次に、次を使用してこれら 2 つのリストを組み合わせることができますJoin

var combinedList = list1.Join(
  list2,
  g1 => g1.Key,
  g2 => g2.Key,
  (g1, g2) => new { Artist = g1.Key, Albums = g1.Union(g2) }
);

一致g1.Keyするg2.Keyことにより、要素がアーティストで一致することが保証されます。アーティストごとにアルバムが作成されg1.Union(g2)ます。

于 2013-09-05T12:05:25.533 に答える