无法使用lightswitch中的代码插入数据
在发布应用程序时提供适当的连接字符串,我能够将使用LS创建的角色,权限和用户映射到ASPNET_Membership表,如aspnet_users SQl Server 2008中的,aspnet_roles等。
Giving appropriate connection string while publishing the application, I'm able able to map the roles, permissions and users created using LS with the ASPNET_Membership tables like aspnet_users, aspnet_roles, etc. in SQl Server 2008.
aspnet_users有像UserId =>这样的列。 uniqueidentifier(datatype),UserName => nvarchar(256)等我创建了另一个表 作为EmployeeDetails,其中包含EmployeeID,Name等列。还有4个列,例如
aspnet_users have columns like UserId => uniqueidentifier(datatype), UserName => nvarchar(256), etc. I have created one more table as EmployeeDetails having columns like EmployeeID, Name,etc. with 4 more columns like
CreatedBy => uniqueidentifier(UserId用作aspnet_Users表中的foreignKey),
CreatedBy => uniqueidentifier (UserId used as foreignKey from aspnet_Users table),
CreatedOn => datetime,
CreatedOn => datetime,
ModifiedBy => uniqueidentifier(UserId用作aspnet_Users表中的foreignKey),
ModifiedBy => uniqueidentifier (UserId used as foreignKey from aspnet_Users table),
ModifiedOn => datetime。
ModifiedOn => datetime.
因此,在网格上显示数据时,我希望看到插入新数据的用户名(在CreatedBy列中)以及之后修改数据的人(在ModifiedBy列中)以及日期。
So while displaying data on grid I would like to see the username who inserted new data (in CreatedBy column) and who modified the data later (in ModifiedBy column) along with the dates.
上述4列(CreatedBy,CreatedOn,ModifiedBy和ModifiedOn)中的数据应该通过编写一些代码自动进行。不应允许用户通过添加数据屏幕为这些列添加数据。
The data in the above 4 columns (CreatedBy, CreatedOn, ModifiedBy and ModifiedOn) should go automatically by writing some code. User should not be allowed to add data for these columns through Add data screen.
您能告诉我在哪里以及如何编写代码来实现此功能吗?此外,当用户登录应用程序时,如何使用上述方案向他显示用户特定数据?
Can you tell me where and how to write a code to achieve this functionality? Also when a user logs in the application, how to show him user-specifc data using above scenario?
(例如: - 如果用户名"abc"已输入2名员工,则登录后他应该只看到那2名员工。
(Eg:- If username "abc" has entered 2 employees, then after login he should see only those 2 employees).
谢谢。
Sandeep,
Sandeep,
您需要访问多个事件才能执行此操作。 要设置CreatedBy和CreatedOn事件,请在EntityName_Created事件中设置值。 使用EntityName_Updating设置ModifiedBy和ModifiedOn。 我相信实体上还有一个
属性来控制在单击表的"添加"按钮时是否显示一行。
There are several events you will want to access to do this. To set the CreatedBy and CreatedOn events, set the values in the EntityName_Created event. Use EntityName_Updating to set ModifiedBy and ModifiedOn. I believe there is also a property on the entity to control whether or not a row is shown when the 'Add' button is clicked for a table.
在屏幕上显示您的实体的数据,您可以删除显示CreatedBy,CreatedOn等的控件,也可以将控件更改为标签。
On the screens that show data for your entity, you can either remove the controls that display CreatedBy, CreatedOn, etc, or you can change the controls to labels.
至于确定当前用户,还有您可以使用的用户对象。 一个有用的身份验证artcile是
http://blogs.msdn.com/b/mthalman/archive/2010/08/23/authentication-features-in-visual-studio-lightswitch .aspx 。
As for as determining the current user, there is a User object available to you. A helpful authentication artcile is at http://blogs.msdn.com/b/mthalman/archive/2010/08/23/authentication-features-in-visual-studio-lightswitch.aspx.
为了实现您谈论的最后一个场景,我相信参数化查询将是您最好的选择。 请参阅
http://msdn.microsoft.com/en-us/library/ff852026.aspx 了解更多信息。
To achieve the last scenario you talk about, I believe a parameterized query would be your best bet. See http://msdn.microsoft.com/en-us/library/ff852026.aspx for more information.
我希望这些信息可以帮助您入门。
I hope this information helps get you started.
问候,
Elizabeth Maher
Elizabeth Maher