I'm using entity framework with C# and I'm unsure how to proceed with this code. My pseudo code is below and I have a list of stock transactions and I'm only trying to insert the transactions that don't exist in the database table but I'm not sure how to write the linq code to do this.
This current code gives me this error:
Argument 1: cannot convert from 'System.Collections.Generic.IEnumerable<System.DateTime>' to 'Finance.Program.HistoryPrice'
public class DailyAmexData
{
public int ID { get; set; }
public string Symbol { get; set; }
public DateTime Date { get; set; }
public decimal Open { get; set; }
public decimal High { get; set; }
public decimal Low { get; set; }
public decimal Close { get; set; }
public decimal AdjustedClose { get; set; }
public int Volume { get; set; }
}
public class HistoryPrice
{
public DateTime Date { get; set; }
public decimal Open { get; set; }
public decimal High { get; set; }
public decimal Low { get; set; }
public decimal Close { get; set; }
public Int32 Volume { get; set; }
public decimal AdjClose { get; set; }
}
using (financeEntities context = new financeEntities())
{
foreach (string symbol in symbols)
{
List<HistoryPrice> hList = Get(symbol, new DateTime(1900, 1, 1), DateTime.UtcNow);
List<DailyAmexData> aList = await (context.DailyAmexDatas.Where(c => c.Symbol == symbol && hList.Contains(hList.Select(i => i.Date)) == false).ToListAsync<DailyAmexData>()); // pseudo code that I wrote so you hopefully understand what I'm trying to do here which is only return a list of DailyAmexData that doesn't exist in the database yet and then save those items to the database
foreach(DailyAmexData item in aList)
{
// insert values of item in database table
}
}
}
UPDATE I made some changes to my question so you can understand what I'm trying to do.