C# WCFTestClient-实体框架中的对象持久性

C# WCFTestClient-实体框架中的对象持久性,c#,wcf,entity-framework,persistence,dbcontext,C#,Wcf,Entity Framework,Persistence,Dbcontext,我正在通过WCFTestClient测试我的WCF服务。我的方法为我运行并返回正确的值。但是,当我从WCFTestClient执行时,我的实体不会持久化。以下是我正在测试的方法: public PlayerActionResult DoAction(PlayerActionType type, int uid, string pparam = null, int amount = 0, string svalue = null) { Player player;

我正在通过WCFTestClient测试我的WCF服务。我的方法为我运行并返回正确的值。但是,当我从WCFTestClient执行时,我的实体不会持久化。以下是我正在测试的方法:

public PlayerActionResult DoAction(PlayerActionType type, int uid, string pparam = null, int amount = 0, string svalue = null) 
    {
        Player player;
        PlayerAction action = (PlayerAction)Activator.CreateInstance(null, string.Concat("Conquest.Players.Actions.", type.ToString())).Unwrap();
        action.Logic = (ActionLogic)Activator.CreateInstance(null, string.Concat("Conquest.Players.Actions.", type.ToString(), "Logic")).Unwrap();
        action.Logic.Action = action;
        // Verify executor exists
        if (!PlayerExists(uid))
        {
            return new PlayerActionResult(false, ResultType.NotFound);
        }
        else { player = GetPlayer(uid); }

        if (pparam != null & !PlayerExists(pparam))
        {
            if (!PlayerExists(pparam))
            {
                return new PlayerActionResult(false, ResultType.NotFound);
            }
            action.playerparam = GetPlayer(pparam);
        }
        PlayerActionResult result = player.DoAction(action);
        player.SaveChanges();
        return result;
    }
当我作为“Player”类构造函数的一部分执行相同类型的逻辑时(Player是从DbContext派生的),所做的更改会保存:

        public Player(int uid, string name)
    {
        this.Name = name;
        this.UserId = uid;
        this.Remorts = 0;
        this.Gender = Gender.Male;
        this.NumAttacks = 3;
        this.Movement = 30;
        this.PlayerClass = PlayerClass.Fighter;
        this.CurrentCont = Helper.GetRandom(3, 1);
        this.Kingdom = new HashSet<Kingdom>();
        this.Kingdom.Add(new Kingdom(this.CurrentCont));
        this.CurrentKingdom.Vault.AddItem(new Item(ItemType.LureVulture));
        this.CurrentKingdom.Vault.AddItem(new Item(ItemType.PotSpeed));
        PlayerAction action = (PlayerAction)Activator.CreateInstance(null, string.Concat("Conquest.Players.Actions.Pray")).Unwrap();
        action.Logic = (ActionLogic)Activator.CreateInstance(null, string.Concat("Conquest.Players.Actions.", "PrayLogic")).Unwrap();
        action.Logic.Action = action;
        this.DoAction(action);
}
public播放器(int-uid,字符串名)
{
this.Name=Name;
this.UserId=uid;
这个.remots=0;
这个。性别=性别。男性;
此参数为0.NumAttacks=3;
这个。运动=30;
this.PlayerClass=PlayerClass.Fighter;
this.CurrentCont=Helper.GetRandom(3,1);
this.Kingdom=newhashset();
this.Kingdom.Add(新王国(this.CurrentCont));
this.CurrentKingdom.Vault.AddItem(新项目(ItemType.LureVulture));
this.CurrentKingdom.Vault.AddItem(新项目(ItemType.PotSpeed));
PlayerAction action=(PlayerAction)Activator.CreateInstance(null,string.Concat(“Conquest.Players.Actions.Pray”)).Unwrap();
action.Logic=(ActionLogic)Activator.CreateInstance(null,string.Concat(“Conquest.Players.Actions.”,“PrayLogic”)).Unwrap();
action.Logic.action=动作;
这就是行动;
}

有谁能告诉我为什么在DbContext派生对象的构造函数中调用此逻辑会持久化数据,而在外部调用逻辑然后使用SaveChanges()则不会

你有所有的datamembers和data Contract设置吗?事实上,我唯一需要在参数中隐式应用属性的是PlayerActionTypes,它在我之前就向我抛出了错误。我没有收到任何错误,就像我的合同和成员设置不正确时一样,事实上没有错误。只是没有坚持。