【问题标题】:Server-generated keys and server-generated values are not supported by SQL Server CompactSQL Server Compact 不支持服务器生成的键和服务器生成的值
【发布时间】:2011-10-05 10:19:13
【问题描述】:

所以我知道 CE 不支持服务器生成的值 - 没关系,我正在提供我自己的代码...

 public static class ExtensionMethods
    {
        public static TResult NextId<TSource, TResult>(this ObjectSet<TSource> table, Expression<Func<TSource, TResult>> selector)
        where TSource : class
        {
            TResult lastId = table.Any() ? table.Max(selector) : default(TResult);

            if (lastId is int)
                lastId = (TResult)(object)(((int)(object)lastId) + 1);
            return lastId;
        }
    }


  private void AddProperty()
        {
            Property p = new Property();     

            entities.AddToProperties(new Property()
            {
            ID = entities.Properties.NextId(u => u.ID),
            AgentName = "Agent Name",
            Address = "New Property",
            AuctioneerName = "Auctioneer Name",
            SaleTitle = "Sales Title",
            DateOfAuction = null,
            ReservePrice = null,
            CurrentBid = null,
            PreviousBid = null,
            });
            entities.SaveChanges();
            BindData();
        }

唯一的问题是,当我认为它应该解决问题时,这并不能解决问题。我有 2 张桌子。一个叫Property,另一个叫Image。两者的ID都设置为主键,唯一的yes,identity为false。我看不出我做错了什么才能得到这个错误,所有其他字段都设置为可为空,但我认为这与这个错误没有任何关系......

【问题讨论】:

  • 你能发布错误信息吗?
  • SQL Server Compact 不支持服务器生成的键和服务器生成的值

标签: c# sql wpf


【解决方案1】:

找到了解决办法,原来我的Identity值无法手动编辑,我不得不重新生成数据库先通过模型创建它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-31
    • 1970-01-01
    • 2010-09-14
    • 1970-01-01
    • 2016-07-24
    • 2014-08-29
    • 1970-01-01
    相关资源
    最近更新 更多