小编Ste*_*ten的帖子

RavenDb期望性能查询数百万的文档

我能够使用嵌入版本的RavenDb加载几百万个文档,非常漂亮!

现在我正在尝试查询这些项目,并且发现性能不是我预期的,尽可能接近瞬间,而是在相当强劲的机器上超过18秒.

下面,你会找到我的天真代码.

注意:我现在已经解决了这个问题,最后的代码位于帖子的底部.需要注意的是,你需要索引,它们必须是正确的类型,并且需要让RavenDB知道它们.非常满意通过查询引擎返回记录的性能和质量.

谢谢你,斯蒂芬

using (var store = new EmbeddableDocumentStore { DataDirectory = @"C:\temp\ravendata" }.Initialize())
{
    using (IDocumentSession session = store.OpenSession())
    {
        var q = session.Query<Product>().Where(x => x.INFO2.StartsWith("SYS")).ToList();
    }
}


[Serializable]
public class Product
{
    public decimal ProductId { get; set; }
    ....
    public string INFO2 { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

编辑

我加了这个班

public class InfoIndex_Search : AbstractIndexCreationTask<Product>
{
    public InfoIndex_Search()
    {
        Map = products => 
            from p in products
                          select new { Info2Index = p.INFO2 };

        Index(x => …
Run Code Online (Sandbox Code Playgroud)

ravendb

4
推荐指数
1
解决办法
1497
查看次数

如果缺少已安装的版本,如何升级 nuget 软件包?

几个月前我遇到了一种情况,我将应用程序部署到生产环境,现在我需要在一台全新的机器上对其进行一些工作。我做的第一件事是拉取源代码,而 nuget restore 将无法恢复,因为它找不到开发它的软件包的特定版本。当我在 nuget.org 上查看此包版本时,它不存在。那么如何将我的解决方案升级到最新的二进制文件呢?

Visual Studio 2013 尝试将 ServiceStack '4.0.39' 更新为最新版本,在本文发布时为 '4.0.40'。

谢谢你,斯蒂芬

nuget servicestack

4
推荐指数
1
解决办法
1246
查看次数

在XML序列化期间删除命名空间

鉴于此通用序列化代码:

public virtual string Serialize(System.Text.Encoding encoding)
{
 System.IO.StreamReader streamReader = null;
 System.IO.MemoryStream memoryStream = null;

 memoryStream = new System.IO.MemoryStream();
 System.Xml.XmlWriterSettings xmlWriterSettings = new System.Xml.XmlWriterSettings();
 xmlWriterSettings.Encoding = encoding;
 System.Xml.XmlWriter xmlWriter = XmlWriter.Create(memoryStream, xmlWriterSettings);
 Serializer.Serialize(xmlWriter, this);
 memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
 streamReader = new System.IO.StreamReader(memoryStream);
 return streamReader.ReadToEnd();
}
Run Code Online (Sandbox Code Playgroud)

和这个对象(来自xsd2code):

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.225")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "Com.Foo.Request")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "Com.Foo.Request", IsNullable = false)]
public partial class REQUEST_GROUP
{

 [EditorBrowsable(EditorBrowsableState.Never)]
 private List<REQUESTING_PARTY> rEQUESTING_PARTYField;

 [EditorBrowsable(EditorBrowsableState.Never)]
 private RECEIVING_PARTY rECEIVING_PARTYField;

 [EditorBrowsable(EditorBrowsableState.Never)]
 private SUBMITTING_PARTY sUBMITTING_PARTYField;

 [EditorBrowsable(EditorBrowsableState.Never)]
 private REQUEST …
Run Code Online (Sandbox Code Playgroud)

c# xml-serialization

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

是否有可以加载和卸载程序集的.NET IoC容器

我正试图找到一个可以实现这一目标的容器.

我想要做的是运行AS.NET网站,而不是在部署程序集中包含的新的或更新的业务规则时卸载/回收AppDomain.这意味着该文件夹位于bin文件夹之外,并且最好在它之上,而不是在它之下(尽管我可以忍受它).我到目前为止所使用的壁橱是使用Autofac和MEF,但似乎没有办法卸载以前加载的组件.

有人可以指点我的资源吗?

谢谢你,斯蒂芬

c# mef autofac

3
推荐指数
1
解决办法
545
查看次数

为什么这个AutoMapper配置不能正确映射?

鉴于下面的代码如下,为什么我在映射阶段一直遇到异常?两个DTO真的那么不同吗?这是抛出异常的符号服务器pdb的代码行.

throw new AutoMapperMappingException(context, "Missing type map configuration or unsupported mapping.");
Run Code Online (Sandbox Code Playgroud)

真正让我感到害怕的是@jbogard在AutoMapper方面完成了异常处理和检测的杀手级工作,源和目标对象都有大量的上下文数据,以及抛出异常时映射器的状态.而我仍然无法弄明白.

void Main()
{
    var config = new MapperConfiguration(cfg =>
    {
        cfg.ShouldMapProperty = p => p.GetMethod.IsPublic || p.GetMethod.IsVirtual;
        cfg.CreateMap<Customer, Customer2>()
        .ReverseMap();
    });

    config.AssertConfigurationIsValid();

    Customer request = new Customer
    {
        FirstName = "Hello", LastName = "World"
    };
    request.FullName = request.FirstName + " " + request.LastName;

    Customer2 entity = Mapper.Map<Customer, Customer2>(request);


    Console.WriteLine("finished");
}



public class Customer
{
    public string FirstName { get; set; }
    public string LastName { get; set; } …
Run Code Online (Sandbox Code Playgroud)

c# automapper

3
推荐指数
1
解决办法
5267
查看次数

如何在运行时启用或禁用 Polly 策略?

在策略的定义中,我希望能够在运行时禁用或启用策略,而不是在调用站点中执行此操作,因为我可能有多个调用站点。

这是我到目前为止的做法吗?

private RetryPolicy<IDisposable> GetRetryPolicy()
{
    if (!this.config.DistributedLockEnabled)
    {
        NoOpPolicy<IDisposable> policy = Policy.NoOp<IDisposable>();
        return policy;
    }

    RetryPolicy<IDisposable> lockPolicy = Policy
        .Handle<TimeoutException>()
        .OrResult<IDisposable>(d => d == null)
        .WaitAndRetry(
            this.config.WorkflowLockHandleRequestRetryAttempts,
            attempt => TimeSpan.FromSeconds(this.config.WorkflowLockHandleRequestRetryMultiplier * Math.Pow(this.config.WorkflowLockHandleRequestRetryBase, attempt)),
            (delegateResult, calculatedWaitDuration, attempt, context) =>
                {
                    if (delegateResult.Exception != null)
                    {
                        this.logger.Information(
                            "Exception {0} attempt {1} delaying for {2}ms",
                            delegateResult.Exception.Message,
                            attempt,
                            calculatedWaitDuration.TotalMilliseconds);
                    }
                });
    return lockPolicy;
}
Run Code Online (Sandbox Code Playgroud)

但可惜的是,这不能编译:)

谢谢你,斯蒂芬

c# polly

3
推荐指数
1
解决办法
1481
查看次数

另一个二维数组分配问题c#

我想弄清楚为什么"选择A"表现得更好"选择B".我的测试显示了228 vs 830或类似的东西,它就像是4倍的差异.看着IL,未经训练的眼睛不会在两个电话之间巧妙地挑选出来.

谢谢你,斯蒂芬

const int SIZE = 10000;
void Main()
{
    var sw = Stopwatch.StartNew();

    int[,]A = new int[SIZE, SIZE];
    int total, x, y;

    // Choice A
    total = 0;
    for (x = 0; x < SIZE; x++)
    {
        for (y = 0; y < SIZE; y++)
        {
            total += A[x, y];
        }
    }

    Console.WriteLine(sw.ElapsedMilliseconds);

    sw.Reset();
    sw.Start();

    // Choice B
    total = 0;
    for (y = 0; y < SIZE; y++)
    {
        for (x = 0; x < SIZE; …
Run Code Online (Sandbox Code Playgroud)

c# arrays

2
推荐指数
1
解决办法
688
查看次数

如何使用单个文本框执行jqGrid的客户端过滤

在客户端使用"filterToolbar"读取了这个QA jqGrid过滤,这个在我发布之前在jqGrid中在加载时触发客户端过滤.有没有办法只使用一个文本框来过滤客户端的数据?

通过在mechanizm中构建的网格加载数据以使用json,我已经设置了loadonce:true,现在的问题是如何实现.

以下是另一个网格插件的示例http://datatables.net/release-datatables/examples/basic_init/zero_config.html

问候,斯蒂芬

jqgrid

2
推荐指数
1
解决办法
7505
查看次数

在单元测试中,您在哪里设置OrmLiteConfig.DialectProvider.NamingStrategy?

我在一个项目中使用ORMLite和Dapper,并希望标准化两个ORM使用的命名约定.为了做到这一点,我想将NamingStrategy设置为:

OrmLiteConfig.DialectProvider.NamingStrategy = new OrmLiteNamingStrategyBase();
Run Code Online (Sandbox Code Playgroud)

和单元测试验证

public class BorrowerUnitTests : IDisposable    
{
    private readonly ServiceStackHost appHost;

    public BorrowerUnitTests()
    {
        //Set ORMLite to work with columns like ColumnLikeThis
        // OrmLiteConfig.DialectProvider.NamingStrategy = new OrmLiteNamingStrategyBase();

        appHost = new BasicAppHost(typeof(BorrowerServices).Assembly)
        {

            ConfigureContainer = container =>
            {

                container.Register<IDbConnectionFactory>(c =>
                    new OrmLiteConnectionFactory(ConfigUtils.GetConnectionString("LoanOrigination:Default"), PostgreSqlDialect.Provider));

                container.RegisterAutoWiredAs<Repository, IRepository>();
                container.RegisterAutoWired<BorrowerDomainService>();
            }

        }
        .Init();
    }

    public void Dispose()
    {
        appHost.Dispose();
    }

    [Fact]
    public void TestPostMethod()
    {
        var service = appHost.Container.Resolve<BorrowerServices>();

        BorrowerCreate request = new BorrowerCreate();
        request.FirstName = "Orm";
        request.LastName = "Lite"; …
Run Code Online (Sandbox Code Playgroud)

unit-testing servicestack ormlite-servicestack

2
推荐指数
1
解决办法
2047
查看次数

jQuery应该只用在ready事件处理程序中吗?

我已经读过使用jQuery在ready处理程序之外的代码,有什么缺点,如果有的话这样使用它?无论出于何种原因,我都对这种方式感到不舒服.

来自和ASP.NET MVC的内联脚本视图:

<script type="text/javascript">
    function foo() {
        if ($("#checkAll").attr("checked")) {
            $(".setColumns").attr("checked", true);
        }
        else {
            $(".setColumns").attr("checked", false);
        }

    }
</script>
Run Code Online (Sandbox Code Playgroud)

javascript jquery

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