I cannot get the data from adc to update to database. I am using LINQ2SQL dbml. I get no sql output from CAPcontext.Log, and Both tables have primary ID's I feel it is an issue with the join in the LINQ query but couldnt find anything on the web regarding it. Can someone point out what am I doing wrong?
CAP_MDF_dataContextDataContext CAPcontext = new CAP_MDF_dataContextDataContext();
public bool LoadCAPadultdaycare()
{
CAPcontext.Log = Console.Out;
var adc = (from v in CAPcontext.AdultDayCares
join s in CAPcontext.States on v.state equals s.Name
select new CAPadultdaycare {
Avg = v.Avg,
City = v.city,
High = v.High,
Low = v.Low,
StateFullName = v.state,
StateAbbr = s.Code
}).ToList();
foreach (var item in adc)
{ item.City = "some city";
// updating more fields but omitted here
}
CAPcontext.SubmitChanges();
return true;
}
My CAPadultdaycare class is...
public class CAPadultdaycare
{
public decimal? High { get; set; }
public decimal? Low { get; set; }
public decimal? Avg { get; set; }
public string Zip { get; set; }
public string City { get; set; }
public string StateAbbr { get; set; }
public string StateFullName { get; set; }
}
You are creating new CAPadultdaycare objects, which are not attached to your data Context and hence not submitted.
The following may work
but this means you are pulling all columns from your database.