小编use*_*622的帖子

添加对象后,实体框架不会加载导航属性

我有MVC项目和EF6模型.

在此输入图像描述

LazyLoading已启用.在控制器中我有以下动作

    public ActionResult AddStage(int projectId, int employeeId)
    {
        using(var context = new TestProjectEntities())
        {
            var project = context.Projects.Find(projectId);
            if (project != null)
            {
                var stage = new Stage() {EmployeeID = employeeId, StageType = 1};
                project.Stages.Add(stage);
                context.Stages.Add(stage);
                context.SaveChanges();
            }

            ListEmployees(project);
        }

        return Redirect("Index");
    }

    private void ListEmployees(Project project)
    {
        var names = new List<string>();
        foreach(var stage in project.Stages)
        {
            if (stage.Employee != null)
            {
                names.Add(stage.Employee.Name);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

但是在foree语句中的ListEmployees方法stage.Employee == null中.为什么?

如果我第二次调用AddStage,那么ListEmployee中的stage.Employee!= null

c# entity-framework entity-framework-6

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

如何在Windows Phone 8.1中创建透明命令栏

如何在Windows Phone 8.1中创建透明命令栏这是xaml

<Page x:Class="App3.MainPage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"      
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  Background="White"      
  mc:Ignorable="d">

<Grid Background="Red" />

<Page.BottomAppBar>
    <CommandBar Background="#CCFFFFFF" Foreground="Black">
        <CommandBar.PrimaryCommands>
            <AppBarButton Label="Button1" />
        </CommandBar.PrimaryCommands>
    </CommandBar>
</Page.BottomAppBar>
Run Code Online (Sandbox Code Playgroud)

当CommandBar打开时,它具有透明背景,但后面有一个白色面板.热门删除此面板?

c# windows-phone-8.1

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