小编Ste*_*yer的帖子

当以斜杠结尾时,RavenDB将整数添加到ID

我使用RavenDB 1.0.0.426

在将数据从外部源导入RavenDB时,我只是经历了一个奇怪的场景:

我选择使用与外部源使用相同的唯一ID,前缀为某个字符串.但.当我存储ID为以'/'结尾的文档时,raven会自动在ID的末尾添加一个数字,导致文档不会覆盖使用相同ID存储的现有文档.

我重新创建了一个简单的场景来导致错误:

我保存的类型:

public class Foo
{
    public string Id { get; set; }
    public Foo(string id)
    {
        Id = id;
    }
}
Run Code Online (Sandbox Code Playgroud)

保存具有相同ID 10次的文档的方法,然后检查文档计数:

public void RunTest(string id)
{
    for (int i = 0; i < 10; i++)
    {
        using (var doc = new DocumentStore() { Url = "http://pc-009:8080/" })
        {
            doc.Initialize();
            using (var session = doc.OpenSession())
            {
                session.Store(new Foo(id));
                session.SaveChanges();
            }
        }
    }

            // Wait for the data to be persisted
            Thread.Sleep(2000);

    using (var doc …
Run Code Online (Sandbox Code Playgroud)

ravendb

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

Javascript - ===和字符串的奇怪问题

我有这个代码:

...
var id1 = playerTick.gameId;
var id2 = that.gameId;
if(id1 === id2)
 {}else{
throw "GameController instantiated with gameId '" + id2 + "' but tick has gameId '" + id1 + "'";
}
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我收到消息:

GameController用gameId'game1'实例化但是tick有gameId'fame1'

如果正确打印'game1'作为两个属性的值,= =如何失败?作为测试,我做了这个工作:

var g = "game1";
var g2 = "game1"
alert(g === g2); // Alerts true
Run Code Online (Sandbox Code Playgroud)

有没有人知道我的===如何失败的任何理论解释但错误信息打印相同的文字?两个值的类型都是对象.

先感谢您.

更新:

问题

事实证明,正如所有回复所指出的那样(并且对此而言),这些类型并不完全相同.其中一个不是导致===评估为false的字符串.

使用此函数检索查询参数后出现问题:

function querystring(key) {
       var re=new RegExp('(?:\\?|&)'+key+'=(.*?)(?=&|$)','gi');
       var r=[], m;
       while ((m=re.exec(document.location.search)) != null) r.push(m[1]);
       return r;
}
Run Code Online (Sandbox Code Playgroud)

固定

function querystring(key) {
           var …
Run Code Online (Sandbox Code Playgroud)

javascript

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

实体框架6 - GetObjectStateEntries预期修改实体具有状态"未更改"

问题

当我创建我的帐户类作为示例A时,对象在我的SaveChanges() - 方法中按预期显示状态为"EntityState.Modified".

当我使用示例B时,该对象显示为"EntityState.Unchanged",并且在GetObjectStateEntries(EntityState.Added | EntityState.Modified)调用的结果中没有apear.

任何人都可以向我解释,为什么模型对象在示例B中看起来没有变化,而一切都在示例A中有效?

谢谢

我在Context对象中使用此方法更新'Created'和'LastUpdated':

public class CrmContext : DbContext
{

public override int SaveChanges()
{
    DateTime now = DateTime.Now;
    foreach (ObjectStateEntry entry in (this as IObjectContextAdapter).ObjectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified))
    {
        if (!entry.IsRelationship)
        {
            var account = entry.Entity as Account;
            if (account != null)
            {
                account.LastUpdated = now;
                if (entry.State == EntityState.Added)
                {
                    account.Created = now;
                }
            }
        }
    }

    return base.SaveChanges();
}

}
Run Code Online (Sandbox Code Playgroud)

模型示例A(工作):

public class Account
{
 [Key]
 public int AccountId { get; …
Run Code Online (Sandbox Code Playgroud)

inheritance entity-framework model

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

XDocument在生成最终的xml字符串时添加回车符

我有一种情况,我想在将XML发布到API之前生成xml,其中包含换行符(\ n)但不包含回车符(no \ r)。

但是在C#中,似乎XDocument会在其to-string方法中自动添加回车符:

var inputXmlString = "<root>Some text without carriage return\nthis is the new line</root>";

// inputXmlString: <root>Some text without carriage return\nthis is the new line</root>

var doc = XDocument.Parse(inputXmlString);

var xmlString = doc.Root.ToString();

// xmlString: <root>Some text without carriage return\n\rthis is the new line</root>
Run Code Online (Sandbox Code Playgroud)

在doc.Root.ToString()中,在缩进元素之间添加了\ n \ r的集合,这对于接收者对xml消息的整体解释并不重要。但是,ToString()方法还在实际文本字段中添加了\ r,我需要在其中保留独立的换行符(在\ n之后没有\ r)。

我知道我可以做最后一个字符串替换,从要执行的实际HTTP发布之前删除最后一个字符串中的所有回车符,但这似乎是错误的。

使用XElement对象而不是Document.Parse构造xml文档时,问题是相同的。即使我使用CData元素包装文本,问题也仍然存在。

任何人都可以向我解释,如果我做错了什么,或者有某种干净的方法来实现自己的目标?

c# xml linq-to-xml

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