0
我父類我的模型:錯誤使用類的模型時,而不是使用元組
public class MyModel
{
public ThemesModel themesModel { get; set; }
public ThemeGroupsModel themesGroupsModel { get; set; }
public ThemeTypsModel themesTypesModel { get; set; }
}
我用它在我的方法:
public List<MyModel> getAllTheme()
{
List<MyModel> myModelList = new List<MyModel>();
MyModel myModelTemp;
using (var context = new EShopThemeDBEntities(idbconnection.ConnStr))
{
var ThemeTypeQ = (//some queries...).ToList();
if (ThemeTypeQ != null)
{
foreach (var item in ThemeTypeQ)
{
myModelTemp = new MyModel();
myModelTemp.themesTypesModel.ThemeTypeName = item.ThemeTypeName;
.
.
.
}
}
}
return myModelList;
}
我就在這行錯誤:
myModelTemp.themesTypesModel.ThemeTypeName = item.ThemeTypeName;
錯誤:
Object reference not set to an instance of an object.
我已經使用Tuple<ThemeTypsModel, ThemesModel, ThemeGroupsModel>
而不是使用MyModel
和我的項目已經工作過。
我該怎麼做才能解決它?