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
Source: stackoverflow.com
Related Query
- How can i fix Cannot implicitly convert Generic.List< > to Generic.List< >
- Cannot implicitly convert type system linq IQueryable to system collections generic List
- How can I sort generic list DESC and ASC?
- How can I convert a list of objects to csv?
- How to convert Generic List<anonymous type > to Generic List <Classname>?
- How can i sort Generic list with Linq?
- Cannot implicitly convert linq result into viewmodel list
- How can I get the average of the elements of a generic list that meet a criteria?
- How can i convert Linq var to List
- How can i copy data table records of different field name based on mapping list evaluating condition on source data table?
- How can I sum values across a generic list using LINQ?
- How to convert LINQ query result to list and return generic List?
- How can I get the next appropriate value from a generic list using LINQ?
- Why did I get an exception "Cannot implicitly convert type 'bool' to 'long?'" when using the LINQ Sum method and how to fix it?
- Linq to object: ToList can not convert to generic list
- How to convert LINQ Query Generic List of Anonymous objects to IEnumerable<object>
- operator '||' cannot be applied to operands of type 'string' and 'string' ( how i can fix this )
- How do I fix an error message of "Cannot implicitly convert type Generic.IEnumerable<type>' to 'Generic.List<type>"
- How to convert Generic List<anonymous type > to Generic List <SubToSubMenu>?
- How can i convert this code snippet into LINQ format?
- How can I select distinct and ordered data into a generic list from multiple lists?
- How can I retrieve an object from a generic list based on the value of two of that object's members?
- How can I include a linq expression to screen a list of generic items
- How to convert data from two tables get from Linq query to List witch can be populated in wpf form
- Cannot convert List to IEnumerable when combining 2 generic lists MVC C#
- LINQ - Cannot implicitly convert type with custom data model list property
- How can convert Xml code to linq
- How can I get the index of an item in a list in a single step?
- C#: How to convert a list of objects to a list of a single property of that object?
- Cannot implicitly convert type 'System.DateTime?' to 'System.DateTime'. An explicit conversion exists
More Query from same tag
- Strange LINQ query error
- Return IQueryable<T> from my method? Is it the right way to do it?
- How to create a where condition to an object inside an object in c# linq?
- Methode Call twice inside LINQ Query
- Linq dynamically adding where conditions
- Create Linq Expression for Sql Equivalent "column is null" in c# by creating linq query dynamically
- C# Turning magic string into lambda expression
- In EF Core, how can I perform a group by and select a list of comma separated values?
- Linq nested query sum
- How can I select the most recent and distinct records and then count the different result types using LINQ?
- C# Data Transformation on Single Object
- Violation of PRIMARY KEY constraint: Cannot insert duplicate key in object
- Can't save changes to database. Store update, insert, or delete statement affected an unexpected number of rows (0)
- entity exception was unhandled by user code
- why datetime.now not work when I didn't use tolist?
- Null exception being thrown by LINQ to EF
- LINQ version of SQL's LIKE statement
- Executing Chain of Responsibility variation
- Using LINQ to XML for simple XML files: overkill? or no worse?
- LINQ to Entities Issue
- Is there a way to merge a collection of duplicated items along with their child collections using LINQ?
- Finding the length of object array, where value is not-empty
- How to use Join in select statement using linq expression
- How can I grab a unique entity set using Linq?
- how to check whether xml file content is in correct format?
- How can I test that my Linq IQueryable has executed
- LINQ Grouping By with Left Join Results
- How can transform this query to linq?
- Can I use linq to achieve the same thing this foreach loop does?
- group by and sum using linq