小编Dev*_*erX的帖子

无法使用Serilog登录MS SQL

我正在使用Serilog和MSSqlServer接收器.即使我按照Serilog.Sinks.MSSqlServer中提到的所有步骤仍然无法在SQL表中记录任何消息.如果您能告诉我哪些部分错过或配置错误,我真的很感激?

以下是我项目中配置代码的部分:

public ILogger Logger = null;

private ColumnOptions _columnOptions = new ColumnOptions
{
    AdditionalDataColumns = new Collection<DataColumn>
    {
        new DataColumn() { AllowDBNull = true, ColumnName = "CreatedBy",DataType = typeof (Guid) },
        new DataColumn() { AllowDBNull = true, ColumnName = "CreatedDate",DataType = typeof (DateTime)},
        new DataColumn() { AllowDBNull = true, ColumnName = "StatusID",DataType = typeof (byte)},
        new DataColumn() { AllowDBNull = true, ColumnName = "ModifiedBy",DataType = typeof (Guid) },
        new DataColumn() { AllowDBNull = true, ColumnName = "ModifiedDate",DataType …
Run Code Online (Sandbox Code Playgroud)

c# sql-server audit-logging serilog

5
推荐指数
1
解决办法
1782
查看次数

为实体框架创建动态表达式

我创建了一个通用表达式构建器,它根据条件集合构建一个谓词。我将谓词传递给存储库中的通用方法。我认为表达式生成器工作正常并创建所需的谓词,尽管实体框架生成的 SQL 脚本与我预期的不一样。我已经阅读了许多关于动态查询或 LinqKit 和表达式构建器的问题和文章,最相关的是这个评论。如果您能查看我所做的并让我知道我是否犯了任何错误,我真的很感激?

下面是 ExpressionBuilder 类的代码:

public static class ExpressionBuilder
{
    private static MethodInfo containsMethod = typeof(string).GetMethod("Contains");
    private static MethodInfo startsWithMethod = typeof(string).GetMethod("StartsWith", new Type[] { typeof(string) });
    private static MethodInfo endsWithMethod = typeof(string).GetMethod("EndsWith", new Type[] { typeof(string) });

    public static Expression<Func<T, bool>> GetExpression<T>(IList<ExpressionModel> filters)
    {
        if (filters == null)
            return null;

        IList<ExpressionModel> nullFreeCollection = filters.OfType<ExpressionModel>().ToList();

        if (nullFreeCollection.Count == 0)
            return null;

        ParameterExpression param = Expression.Parameter(typeof(T), "item");
        Expression exp = null;

        if (nullFreeCollection.Count == 1)
            exp …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework expression-trees dynamic-linq

5
推荐指数
1
解决办法
1万
查看次数