0

Today I played a little bit with LightSwitch in VisualStudio 2012. I've following problem:

I have a database created by EntityFramework (code first) with GUIDs as the primary key on every table.

I used this database as the data source for my LightSwitch project.

Now on creating a new item with LightSwitch, of course I want to hide the primary key from the user, as it is generated by the database. Unfortunately the gui keeps validating the field, even if I remove it from the screen. I can't save a new item, because the validation wants me to enter a value for the primary key field.

I think I'm not using a totally uncommon setup, so how to solve this simple problem?

I've already tried to pre-populate the guid in the created event on the server side, but even if I include the field on the screen, it is still empty...

4

2 回答 2

1

我发现创建的代码实际上并没有运行,直到您尝试首先插入实体(由于验证错误,它永远不会到达)

我找到的解决方案(这并不理想)是用带有空 guid ("00000000-0000-0000-0000-000000000000")] 的 javascript 填充 id,然后在 entity_inserting(..) 中覆盖它

这并不理想,因为客户端会因为服务器上的 ID 与其 ID 不同而感到困惑。

据说,应该在数据库中生成 ID,但我没有任何运气。

于 2013-09-10T05:26:38.383 回答
1

我发现的另一个更好的解决方案是设置一个为 GUID 提供服务的控制器,然后在客户端获取这些 guid。

这将允许客户端能够在不刷新页面的情况下引用该对象。

如果您想要一些代码来做到这一点,只需评论或投票或其他东西..

于 2013-09-12T22:42:47.587 回答