i am trying to insert data into database table using sqlBulkCopy it works fine data is inserted, then I would like to query my data but when I referenced to the updated table, I am getting error: object is null. I am able to see this table using entity structure but value of this object is null:
using (var cn = new AdventureWorksEntities())
{
cn.Database.ExecuteSqlCommand("TRUNCATE TABLE tmpTable");
sqlConnectionString = cn.Database.Connection.ConnectionString;
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString))
{
bulkCopy.DestinationTableName = "dbo.tmpTable";
try
{
// Write from the source to the destination.
bulkCopy.WriteToServer(table);
}
catch (Exception ex)
{
//ErrorHandler
}
}
// Now I am trying to get data from the updated table:
var uniqueItemIDs = cn.tmpTable.Select(m => m.ItemID).Distinct();
// And from the line above I am getting the Error: tmpTable is null.
}
other tables (that weren't updated using SqlBulkCopy) are fine and accessible. Can somebody help?