How to Change Asp.net Core Identity AspNetUsers Role Primary key Data Type - asp.net-core

I am trying to change the Data Type of .NET core Identity AspNetUsers primary key data type from GUID to Int. but couldn't find a way. What can I do to change only AspNetUsers primary key data type.

on model creating event
modelBuilder.Entity<ApplicationUser>(b =>
{
// Primary key
b.HasKey(u => u.Id).HasColumnType("int");
//other configuration
});
then run in package manager console
Run Update-Database

Related

Microsoft Identity Extending tables

ello
I am using Microsoft identity in my asp.net core project and i extended the table AspNetUsers by inherit from it a class called appicationUsers, after that i created many tables related to my own project and linked those table with the mentioned one (appicationUsers). when i migrate the DbContext to the database (sql server) two tables have been created (appicationUsers, AspNetUsers) and the relations created between ApplicationUsers and the rest of my tables not between AspNetUsers and them, also when i run the application and started to create users, they were loaded in AspNetUsers table.. so my question is ... how can my tables access to AspNetUsers table if no relation between them??
in this case make a relation between ApplicationUsers and AspNetUsers
like this inside ApplicationUsers entity:
public string IdentityUserId{get;set;}
public AspNetUsers IdentityUser{get;set;}
then update your database and fill IdentityUserId with a field which mutual between theses two tables like email or name etc.
then fix your create user code and add aspnetusers.id inside applicationuser.IdentityUserId while creating a new user.
after these actions you can access aspnetusers through other tables like this
context.Table.ApplicationUser.IdentityUser
or something like join in sql server

Why is Asp.net core identity add migration is first dropping table and creating again

I am adding a field in Asp.Net Core Identity
public class ApplicationUser : IdentityUser
{
public string Permissions { get; set; }
}
But when i add migration it first drop tables then add column and at the end it recreate tables. But i have some references in other tables so i don't want to delete AspNetUser table
I added the migration and class is created
When i update database
update-database -Context ApplicationDbContext
then error is occured
There is already an object named 'AspNetRoles' in the database.

VSTS-Build for SQL server project is not working

I have an Azure SQL Server database that I am trying to put into TFS. I have created project and imported database, but when I try to do a build in Visual Studio I get the following error:
"SQL71589: Master Key must be created before a database scoped
credential".
You need to create scoped credentials for your database. See this MSDN article:
https://learn.microsoft.com/en-us/sql/t-sql/statements/create-database-scoped-credential-transact-sql?view=sql-server-2017
Depending on your scenario, the code will look something like this:
-- Create a db master key if one does not already exist, using your own password.
CREATE MASTER KEY ENCRYPTION BY PASSWORD='<EnterStrongPasswordHere>';
-- Create a database scoped credential.
CREATE DATABASE SCOPED CREDENTIAL AppCred WITH IDENTITY = 'dbUserNameFooBar',
SECRET = '<EnterStrongPasswordHere>';
GO
Hope that helps.

ZF2, doctrine and Authentication

I have used doctrine 2 and ZF2.
After login to system, i am using ZF2 authentication class (Zend\Authentication\Authenticationservie.php ) and create one identity.
Now my Identity contains some required values of user (which is further useful and can be fetched), but i have one functionality which update user values which are also in identity, so in this case I need to update existing entity values. otherwise i have to relogin to update entity.
How can i achieve this? there is no function available to update existing entity in Zend\Authentication\Authenticationservie.php
ZF2 authentication service use a storage container, in wich the identify data is being stored. you can write to this container with $this->getStorage()->write( $myData )
so you update the identity with something like this
// benutzer entity update
$benutzer->setSomeMethodSetTo('newValue');
// doctrine update
$entityManager->persist( $benutzer );
$entityManager->flush();
// write updated benutzer to
$authService = $this->getServiceManager()->get('Zend\Authentication\Authentication');
$authService->getStorage()->write( $benutzer );

unable to fetch data from link table using WCF

I have a aspnet_Users table with UserD as primary key and master_actor table with ActorID as primary key and have no common key..
The two tables are linked together using a link table master_actorlink table with UserID and ActorID columns..
I want to fetch the ActorID of master_actorlink table using the UserID via WCF services..
I'm new to WCF so plz help
Assuming you have security enabled, you can pull the username from the Identity context.
OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name
More information on Identity & WCF Security Context