我有一个名为background-color: rgba(46, 204, 113, 0.4); border: none;
的方法,如下所示:
RevertChanges
我知道无论public static void RevertChanges<TEntity>()
{
var jsonData = DataAccess.GetEnvironmentJson((int)Environments.Production);
var model = JsonConvert.DeserializeObject<Models.FullDataSetModel>(jsonData);
var targetEntity = typeof(TEntity).Name;
using (var db = new LoginPageContentEntities())
{
db.Database.ExecuteSqlCommand(String.Format("TRUNCATE TABLE [{0}]", targetEntity));
var modelValue = model.GetType().GetProperty(targetEntity).GetValue(model, null);
var table = (DbSet)(typeof(LoginPageContentEntities).GetProperty(targetEntity).GetValue(db, null));
table.AddRange((DbSet)modelValue);
db.SaveChanges();
}
}
是什么,都会匹配modelValue数据集。 DbSet转换不起作用,我正在努力找到如何使用泛型返回整个实体。我发现,如果我使用TEntity
进行投射,我可以在桌面上调用(IEnumerable<TEntity>)
,但这不起作用,因为我需要能够调用添加范围。有可能:
ToList()
保存上下文?对于上下文,我试图替换此方法:
AddRange
型号:
public static void RevertChanges(Environments targetToRestoreFrom, ContentFields tableToRevert)
{
var jsonData = DataAccess.GetEnvironmentJson((int)targetToRestoreFrom);
var model = JsonConvert.DeserializeObject<Models.FullDataSetModel>(jsonData);
using (var db = new LoginPageContentEntities())
{
switch (tableToRevert)
{
case ContentFields.ProductInformation:
db.Database.ExecuteSqlCommand("TRUNCATE TABLE [ProductInformation]");
db.ProductInformation.AddRange(model.ProductInformation);
break;
case ContentFields.DidYouKnow:
db.Database.ExecuteSqlCommand("TRUNCATE TABLE [DidYouKnow]");
db.DidYouKnow.AddRange(model.DidYouKnow);
break;
case ContentFields.MaintenanceMessage:
db.Database.ExecuteSqlCommand("TRUNCATE TABLE [MaintenanceMessage]");
db.MaintenanceMessage.AddRange(model.MaintenanceMessage);
break;
case ContentFields.TrainingEvent:
db.Database.ExecuteSqlCommand("TRUNCATE TABLE [TrainingEvents]");
db.TrainingEvents.AddRange(model.TrainingEvents);
break;
case ContentFields.VideoContent:
db.Database.ExecuteSqlCommand("TRUNCATE TABLE [HtmlSnippets]");
db.HtmlSnippets.AddRange(model.HtmlSnippets);
break;
case ContentFields.ProductMarketingUrl:
db.Database.ExecuteSqlCommand("TRUNCATE TABLE [ProductMarketingUrl]");
db.ProductMarketingUrl.AddRange(model.ProductMarketingUrl);
break;
}
db.SaveChanges();
}
}