score:1

Accepted answer

i am not sure why you're doing that. can i suggest this?

you do not need to go all that way of creating a class that joins the two. just create a navigation property on your rp that points to rphistory objects.

public class rp 
{
    public int id { get; set; }
    public int rpid { get; set; }
    public string name { get; set; }
    public int productid { get; set; }
    public icollection<rphistory> historylist { get; set; } // navigation property
}

public class rphistory: 
{
    public int id { get; set; }
    public int rpid { get; set; }
    public string name { get; set; }
    public int productid { get; set; }

    [foreignkey(nameof(rpid))] // identify the foreign key from rp class
    public rp rp { get; set; } // navigation back to rp
}

then you can chain everything into a single list using linq:

var rps = context.rp.where(rp => rp.productid  == request.id)
                 .include(rp=>rp.rphistory) // this includes rphistory
                 .tolist();

score:1

you need to clone or create a new list.

option 1: use convertall

list<rphistory> pphistorycopy = rphwithhistory.rphistory.convertall(history => new rphistory(rphwithhistory.rphistory));

option 2:

//clone extension
static class extensions
{
    public static ilist<t> clone<t>(this ilist<t> listtoclone) where t: icloneable
    {
        return listtoclone.select(item => (t)item.clone()).tolist();
    }
}

use the clone extention


Related Query

More Query from same tag