I want to write a custom class extension. I have EDMX class but I want to parse to CUSTOM class. For example Customer Class has 3 properties (id, name, surname) on the other hand my Custom Customer Class has 3 properties (id, name, surname). I want to parse List<Customer> to List<MyCustomer> with using an extension but how can I do that?
public partial class MyVisitorAdvertisement
{
public int ID { get; set;}
public int VID { get; set;}
public int TID { get; set;}
public string Detail{ get; set;}
public DateTime Date { get; set;}
public DateTime LastDate { get; set;}
public MyVisitorAdvertisement()
{
//constructor
}
public List<MyVisitorAdvertisement> ListByID( int ID)
{
List<MyVisitorAdvertisement> visitors = new List<MyVisitorAdvertisement>();
using (var Ctx = new DomainRepository<VisitorAdvertisement>(new ProposalsEntities()))
{
foreach (var visitor in Ctx.Find<VisitorAdvertisement>(q => q.ID == ID).ToList())
{
MyVisitorAdvertisement visitoradvertisement = new MyVisitorAdvertisement();
visitoradvertisement.ID = visitor.ID;
// i dislike to do it. i think that how to make it a extention?
visitors.Add(visitoradvertisement);
}
return visitors;
}
}
}
My desired extension:
public static List<TResult> (this IEnumerable<T> mylist) where TResult,T: class
{
return //mylist parse to List<TResult>
}
Something like:
If VisitorAdvertisement inherited from a base entity that had the ID in it then you could base the resriction on that instead opening up to anything derived from it. Sorry I keep get the syntax wrong, I’m not coding this in VS.Net