Czesz, mam problem z klasą zawierającą statyczne elementy:
public class OfferPriceModel
{
public int OfferID { get; set; }
public int Period { get; set; }
public double Price { get; set; }
public static int PeriodBuilder(int year, int month)
{
return Convert.ToInt32(string.Format("{0}{1}", year, month));
}
public static List<OfferPriceModel> GetData = SqlOperations.GetData("olx.t_offer_price").Tables[0].AsEnumerable().Select(x => new OfferPriceModel()
{
OfferID = x.Field<int>("OfferID"),
Period = x.Field<int>("Period"),
Price = x.Field<double>("Price")
}).ToList();
public static void Save(OfferPriceModel model)
{
SqlOperations.ExecProc("olx.p_offer_price", new SqlParameter[]
{
new SqlParameter("@OfferID", model.OfferID),
new SqlParameter("@Period", model.Period),
new SqlParameter("@Price", model.Price)
});
}
}
Klasa ta zwraca wyjątek TypeInitializationException
Po prześledzeniu to zauważyłem, że ten fragment kodu powoduje wyjątek:
public static List<OfferPriceModel> GetData = SqlOperations.GetData("olx.t_offer_price").Tables[0].AsEnumerable().Select(x => new OfferPriceModel()
{
OfferID = x.Field<int>("OfferID"),
Period = x.Field<int>("Period"),
Price = x.Field<double>("Price")
}).ToList();
W projekcie mam kilka takich klas i w pozostałych nie występuje ten problem, co w tym przypadku może być powodem?