开发者

ASP.NET Entity Framework Guid

开发者 https://www.devze.com 2023-01-28 09:58 出处:网络
Using the Entity Framework that I generated. I have a Roles table created during the default system AspNetSqlRoleProvider security set-up.

Using the Entity Framework that I generated. I have a Roles table created during the default system AspNetSqlRoleProvider security set-up.

In the Roles table, I have an ApplicationId uniqueidentifi开发者_运维知识库er column. Which has a guid populated in it, which doesn't change for my application.

I need to add a Role manually through my app using the entity framework. However, when creating my Roles object and setting Roles.ApplicationId. It expects a type of Guid. I have the ApplicationId in my web.config app settings. As it shouldn't change. But it is returned at string. I cannot type cast the value either to use in Roles.ApplicationId.

What can I do to use my current ApplicationId value when trying to create a new role manually using the EF?


You're going to have to convert to a Guid, but that's easy to do. The constructor takes a string value that's the GUID form (new Guid("..")), or I think there may be a Parse method too.

HTH.

0

精彩评论

暂无评论...
验证码 换一张
取 消