有人用过Ndatabase对象数据库么,有点问题想咨询下

abutwang 2013-11-21 09:50:37
/// <summary>
/// 添加或更新
/// </summary>
/// <param name="name"></param>
public void StoreOrUpdate(string name)
{
var sport = new Sport(name,new DateTime(2001,1,12));
using (var odb = OdbFactory.Open("test.db"))
{
var query = odb.Query<Sport>();
query.Descend("Name").Constrain(name).Equal();
List<Sport> spotlst = query.Execute<Sport>().ToList<Sport>();
// Store the object
if (spotlst.Count == 0)// 执行查询
{
odb.Store<Sport>(sport);// 保存usermodel对象。
}
else
{
for (int i = 0; i < spotlst.Count; i++)
{
spotlst[i].Dt = DateTime.Now;
odb.Store<Sport>(spotlst[i]);
}
}
}
}



当反复执行此方法进行更新数据时我发现test.db数据文件不断增大

但是问题是我仅仅是update啊
http://download.csdn.net/detail/ruanjianderen/5311887
程序是在csdn上下的很奇怪啊




...全文
195 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
abutwang 2013-11-21
  • 打赏
  • 举报
回复
自己再顶下吧
abutwang 2013-11-21
  • 打赏
  • 举报
回复
引用 1 楼 happy09li 的回复:
http://developer.51cto.com/art/201302/380454.htm 看看相关资料
看过了,你可以试试看他那些资料,如果你每秒钟修改,你会发现数据文件很大很大
熙风 2013-11-21
  • 打赏
  • 举报
回复
abutwang 2013-11-21
  • 打赏
  • 举报
回复
/// <summary> /// Store an object with the specific id /// </summary> /// <param name="oid"> </param> /// <param name="plainObject"> </param> private OID InternalStore<T>(OID oid, T plainObject) where T : class { if (GetSession().IsRollbacked()) { throw new OdbRuntimeException( NDatabaseError.OdbHasBeenRollbacked.AddParameter(GetBaseIdentification().ToString())); } if (plainObject == null) throw new OdbRuntimeException(NDatabaseError.OdbCanNotStoreNullObject); var type = typeof (T); if (OdbType.IsNative(type)) { throw new OdbRuntimeException( NDatabaseError.OdbCanNotStoreNativeObjectDirectly.AddParameter(type.FullName).AddParameter( OdbType.GetFromClass(type).Name).AddParameter(type.FullName)); } // first detects if we must perform an insert or an update // If object is in the cache, we must perform an update, else an insert var cache = GetSession().GetCache(); var cacheOid = cache.IdOfInsertingObject(plainObject); if (cacheOid != null) return cacheOid; // throw new ODBRuntimeException("Inserting meta representation of // an object without the object itself is not yet supported"); var mustUpdate = cache.Contains(plainObject); // The introspection callback is used to execute some specific task (like calling trigger, for example) while introspecting the object var callback = _introspectionCallbackForInsert; if (mustUpdate) callback = _introspectionCallbackForUpdate; // Transform the object into an ObjectInfo var nnoi = (NonNativeObjectInfo) _objectIntrospector.GetMetaRepresentation(plainObject, true, null, callback); // During the introspection process, if object is to be updated, then the oid has been set mustUpdate = nnoi.GetOid() != null; return mustUpdate ? _objectWriter.UpdateNonNativeObjectInfo(nnoi, false) : _objectWriter.InsertNonNativeObject(oid, nnoi, true); }
abutwang 2013-11-21
  • 打赏
  • 举报
回复
public override OID Store<T>(OID oid, T plainObject) { if (IsDbClosed) { throw new OdbRuntimeException( NDatabaseError.OdbIsClosed.AddParameter(DbIdentification.Id)); } var newOid = InternalStore(oid, plainObject); GetSession().GetCache().ClearInsertingObjects(); return newOid; }
abutwang 2013-11-21
  • 打赏
  • 举报
回复
引用 9 楼 caozhy 的回复:
[quote=引用 6 楼 abutwang 的回复:] [quote=引用 5 楼 caozhy 的回复:] 看它的源代码就知道。更新数据其实是删除再插入实现的。
那为什么test.db数据文件只大不小呢[/quote] 我没有说清楚。删除其实就是将那块存储标记为无数据。不会将后面的数据移动,填充这个位置。 你看下源代码不就知道了。[/quote] 刚在下这个代码呵呵,第一次用这种东西 说真的如果这种量级的对象数据库真可以用于实际的话 对于小型桌面的应用方便很多啊呵呵
threenewbee 2013-11-21
  • 打赏
  • 举报
回复
引用 8 楼 abutwang 的回复:
这算不算Bug?
这不算bug。这样的实现最简单。而且性能比较好。
threenewbee 2013-11-21
  • 打赏
  • 举报
回复
引用 6 楼 abutwang 的回复:
[quote=引用 5 楼 caozhy 的回复:] 看它的源代码就知道。更新数据其实是删除再插入实现的。
那为什么test.db数据文件只大不小呢[/quote] 我没有说清楚。删除其实就是将那块存储标记为无数据。不会将后面的数据移动,填充这个位置。 你看下源代码不就知道了。
abutwang 2013-11-21
  • 打赏
  • 举报
回复
这算不算Bug?
abutwang 2013-11-21
  • 打赏
  • 举报
回复
test.db数据记录或者说是保存的对象的确是只有一个 但是哪个数据库文件真是不断再变大
abutwang 2013-11-21
  • 打赏
  • 举报
回复
引用 5 楼 caozhy 的回复:
看它的源代码就知道。更新数据其实是删除再插入实现的。
那为什么test.db数据文件只大不小呢
threenewbee 2013-11-21
  • 打赏
  • 举报
回复
看它的源代码就知道。更新数据其实是删除再插入实现的。
abutwang 2013-11-21
  • 打赏
  • 举报
回复
自己再顶下吧

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧