DataTable dt = ds.Tables[4].AsEnumerable()
.Where(x => ((DateTime)x["EndDate"]).Date >= DateTime.Now.Date)
.CopyToDataTable();
Run Code Online (Sandbox Code Playgroud)
ds.Tables[4] 有行,但它抛出异常
"源不包含DataRows."
知道如何处理或摆脱这种异常吗?
我重写了SaveChange()方法.我想要的是用简单的文本记录对实体所做的所有更改,例如"abc updated Name john to doe,..."等我已经实现了功能但是当实体中有一个外键要更新时像country_Id指出国家它生成的文本像"abc updated Country_Id 1 to 3,..."这就是我不想要它应该是这样的"abc更新国家加拿大到澳大利亚,......"
因此,要实现这一点,它应该知道外键及其值
我的代码是:
public override int SaveChanges()
{
List<string> listChanges = new List<string>();
List<string> listTable = new List<string>();
var objectStateManager = ((IObjectContextAdapter)this).ObjectContext.ObjectStateManager;
IEnumerable<ObjectStateEntry> changes =
objectStateManager.GetObjectStateEntries(EntityState.Modified | EntityState.Added | EntityState.Deleted);
foreach (ObjectStateEntry stateEntryEntity in changes)
{
var modifiedProperties = stateEntryEntity.GetModifiedProperties();
foreach (var propName in modifiedProperties)
{
if (Convert.ToString(stateEntryEntity.OriginalValues[propName]) != Convert.ToString(stateEntryEntity.CurrentValues[propName]))
{
listTable.Add(stateEntryEntity.EntityKey.EntitySetName);
listChanges.Add(propName + " From " + Convert.ToString(stateEntryEntity.OriginalValues[propName]) + " to " + Convert.ToString(stateEntryEntity.CurrentValues[propName]));
}
//System.Console.WriteLine("Property {0} changed from …Run Code Online (Sandbox Code Playgroud) _dbEntities.EmployeeAttendances.Where(x => x.DailyDate.Date.Equals(DateTime.Now.Date)).ToList();
Run Code Online (Sandbox Code Playgroud)
"LINQ to Entities不支持指定的类型成员'Date'.仅支持初始值设定项,实体成员和实体导航属性."
如何根据linq查询中的当前日期获取员工数据?
var result = (from t1 in _dbEntities.Charges
join t2 in _dbEntities.ChargesTypes on t1.ChargesTypeID equals t2.ID
where t1.StudentID == 1033
select new {t2.Amount}).SingleOrDefault();
Run Code Online (Sandbox Code Playgroud)
我想总结一下amount如何做到这一点,它应该int在总结之前转换成