我正在尝试创建一个linq-to-sql对象的列表,稍后我将添加到DataContext并插入该列表。当我调用SubmitChanges()时,我得到一个错误,说明WeatherForecast对象的Postcode外键为空。
当调用list.add()时,它不会对依赖对象进行深度复制。有没有办法让它做一个深度复制?
这是我想做的一个例子。
function List<WeatherForecast> CreateForecast(Postcode postcode)
{
var forecasts = List<WeatherForecast>();
var wf = new WeatherForecast()
{
ForecastDate = DateTime.Today
, CurrentTemperature = (decimal)today.Attribute(XName.Get("temperature"))
};
wf.Postcode = postcode;
forecasts.Add(wf);
...
Keep adding forecast objects into the list
...
return forecasts;
}