1

在我们的计划中,LLBLGEN 中有大约 50 多个实体。它们都有 2 列,称为ModifyDatetimeModifyUserID。它们也是 SQL 数据库中每个表的最后 2 列。

我们想修改 .Save() 的 LLBLGEN 函数,以便在程序员执行 .Save()有一个会话变量和要在所有实体上发送的当前时间

我得到它是为了保存会话用户 ID 和日期时间,但在某些情况下会出错,我认为这与在渲染或编译时更改的列的位置有关。

我从 ___Entity.cs 之一(在本例中为 CityEntity.cs)复制了 2 个公共虚拟函数,它甚至在保存另一种实体类型(ServicesEntity.cs)时也有效。所以,有一段时间,我认为 CityFieldIndex.* 只是一个随机整数。两个类都有不同数量的列。或者也许我不完全理解这个公共虚拟以及如何覆盖它。

我还尝试发送 Rows.Count - 1 和 Rows.Count - 2 而不是 CityFieldIndex.*

在 set ModifyUserId 上也出现一个奇怪的错误:值 33 的类型为“System.Int32”,而该字段的类型为“System.Nullable`1[System.DateTime]”(33 是用户 ID)

CommonEntityBase.cs上的自定义代码是:

public override bool Save(IPredicate updateRestriction, bool recurse)
{
      System.Diagnostics.Debug.WriteLine("i'm overriding SAVE yeii");
      ModifyDatetime = DateTime.Now;
      ModifyUserId = 33;

      return base.Save(updateRestriction, recurse);
}

public virtual Nullable<System.DateTime> ModifyDatetime
{
    get { return (Nullable<System.DateTime>)GetValue((int)CityFieldIndex.ModifyDatetime, false); }
    set { SetValue((int)CityFieldIndex.ModifyDatetime, value, true); }
}    

public virtual Nullable<System.Int32> ModifyUserId
{
    get { return (Nullable<System.Int32>)GetValue((int)CityFieldIndex.ModifyUserId, false); }
    set { SetValue((int)CityFieldIndex.ModifyUserId, value, true); }
}
4

1 回答 1

0

我解决了。
现在,每当其他人使用 Save() 时,它都会从会话中保存用户。如果没有用户集,它只是放置 UserId = 0。

当然,我们关闭了我们的应用程序来验证登录会话,只有系统服务使用 0 保存:)

 public override bool Save(IPredicate updateRestriction, bool recurse)
    {
        ModifyDatetime = DateTime.Now;
        int userID = 0;

        // Verifies the UserId that called the Save(). Uses 0 (as system user) when none is found.
        try
        {
            if (HttpContext.Current.Session["UserID"] != null)
            { userID = Convert.ToInt32(HttpContext.Current.Session["UserID"]); }

        }
        catch (NullReferenceException nullE)
        {
            userID = 0;
        }
        ModifyUserObjectId = userID;

        return base.Save(updateRestriction, recurse);
    }

    /// <summary> The ModifyDatetime property of all Entities<br/><br/></summary>
    /// <remarks>All tables must have the field: *table*."modifyDatetime"<br/>
    public virtual Nullable<System.DateTime> ModifyDatetime
    {
    //    get { return (Nullable<System.DateTime>)GetValue((int)base.Fields["ModifyDatetime"].FieldIndex, false); }  // uncomment for GET
        set { SetValue((int)base.Fields["ModifyDatetime"].FieldIndex, value, true); }
    }

    /// <summary> The ModifyUserObjectId property of all Entities<br/><br/></summary>
    /// <remarks>All tables must have the field: *table*."modifyUser_objectID"<br/>
    public virtual Nullable<System.Int32> ModifyUserObjectId
    {
    //    get { return (Nullable<System.Int32>)GetValue((int)base.Fields["ModifyUserObjectId"].FieldIndex, false); }  // uncomment for GET
        set { SetValue((int)base.Fields["ModifyUserObjectId"].FieldIndex, value, true); }
    }

仍然不知道它是否适用于集合。但它应该是相同的代码。

于 2012-12-08T21:02:23.703 回答