小编Die*_*iro的帖子

实体框架代码中的DbUpdateConcurrencyException优先

我遇到了Entity Framework和Code First的问题.我有一个具有Timestamp属性的实体,我向数据库添加一条新记录,调用SaveChanges,一切正常.当我尝试删除刚刚添加的记录时,我收到以下消息:

存储更新,插入或删除语句会影响意外的行数(0).自实体加载后,实体可能已被修改或删除.刷新ObjectStateManager条目.

在我看来,EF并不知道这个新记录存在于数据库中,尽管它存在.有时,即使我尝试更新不同的记录,我也会得到相同的消息,但是如果我尝试删除不同的记录,它就会起作用.

有谁知道为什么会这样?

先谢谢,迭戈

编辑 我已经汇编了一些代码,以便更容易理解我的问题:

我有两个简单的实体:

public class Entidade1
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int ID { get; set; }

    public string Descricao { get; set; }

    [Timestamp]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public byte[] RecTS { get; set; }
}

public class Entidade2
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int ID { get; set; }

    public string Descricao { get; set; }

    [Timestamp]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public byte[] RecTS { get; set; }

    public virtual Entidade1 Entidade1 { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

上下文:

public …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-4 ef-code-first

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

Workflow Foundation - 在自定义设计器中分配InArgument

我在Workflow Foundation中使用自定义活动和设计器时遇到问题.为了这个问题,我创建了一个非常简单的活动,如下所示:

[Designer(typeof(TesteDesigner))]
public sealed class Teste : CodeActivity
{
    // Define an activity input argument of type string
    [RequiredArgument]
    public InArgument<string> Text { get; set; }

    // If your activity returns a value, derive from CodeActivity<TResult>
    // and return the value from the Execute method.
    protected override void Execute(CodeActivityContext context)
    {
        // Obtain the runtime value of the Text input argument
        string text = context.GetValue(this.Text);
    }
}
Run Code Online (Sandbox Code Playgroud)

设计师如下:

<sap:ActivityDesigner x:Class="ActivityDesignerLibrary1.TesteDesigner"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
                      xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation"
                      xmlns:System="clr-namespace:System;assembly=mscorlib"
                      xmlns:Converters="clr-namespace:System.Activities.Presentation.Converters;assembly=System.Activities.Presentation">
    <sap:ActivityDesigner.Resources>
        <Converters:ArgumentToExpressionConverter x:Key="ArgumentToExpressionConverter" …
Run Code Online (Sandbox Code Playgroud)

c# wpf workflow-foundation-4

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

主要密钥与实体框架代码的一对一关系

当我尝试使用Code First创建一对一关系时,我当前收到以下错误:System.Data.Edm.EdmAssociationEnd :: Multiplicity在关系'C001_Holding_Teste_C001_Holding'中的角色'C001_Holding_Teste_C001_Holding_Source'中无效.由于从属角色是指关键属性,因此从属角色的多重性的上限必须为1.我的实体定义如下:

[Table("C001_Holding", Schema = "Cad")]
public partial class C001_Holding
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int C001_Id { get; set; }

    [MaxLength(16)]
    public string C001_Codigo { get; set; }

    [MaxLength(100)]
    public string C001_Descricao { get; set; }
}

public class C001_Holding_Test
{
    [Key]
    public int C001_Id { get; set; }
    [MaxLength(100)]
    public string C001_TestInfo { get; set; }

    [ForeignKey("C001_Id")]
    public virtual C001_Holding C001_Holding { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我不想用Fluent创建这些关系,有谁知道为什么会这样?

韩国社交协会.

entity-framework ef-code-first

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