【发布时间】:2015-09-30 11:43:10
【问题描述】:
我是电灯开关的新手,
我正在使用 MVC 进行灯光开关。
让我解释一下我的场景:
首先我创建了一个电灯开关应用程序。在这个应用程序中,有一个项目称为 [ProjectName].Server
然后我在 Light-Switch 应用程序中连接了我的 SQL 数据库。并通过 Light-Switch 屏幕尝试 CRUD 操作,它的工作正常。
在这个服务器项目中,我创建了 MVC 结构,如控制器、模型和视图。使用Click Here
然后我在 Home 控制器中创建了简单的索引视图并成功打开。(通过桌面客户端打开浏览器)
现在我想通过实体框架或灯开关数据上下文在我的控制器中获取灯开关表数据(记录)。建议我最简单的方法..
我不知道如何使用灯开关数据上下文在控制器中获取数据。所以我尝试了使用 DbContext 和 DbSet 的实体框架。
但我得到了错误:
One or more validation errors were detected during model generation:
LightSwitchApplication.Data.[EntityName]: EntityType '[EntityName]' has no key defined. Define the key for this EntityType.
[EntityName]: EntityType: EntitySet '[EntityName]' is based on type '[EntityName]' that has no keys defined.
我还在这里Click Here 获得了一些灯开关数据上下文的解决方案
我尝试实现但没有得到 ApplicationData 和 CreateContext 见附件。
你的回答会很明显
谢谢,
贾丁
【问题讨论】:
标签: c# asp.net-mvc entity-framework lightswitch-2013