Skip to content

Commit cf80544

Browse files
committed
Update crud.md
1 parent c36bb0f commit cf80544

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

MyApp/_pages/crud.md

+87
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,93 @@ public class Todo
496496
}
497497
```
498498

499+
### Modifying ApplicationUser
500+
501+
In many cases the AI Models will want to generate a `User` class for their AI models. But as Blazor Apps
502+
are already configured to use an ApplicationUser Identity Auth User class, the C# code generation only generates
503+
the User class in a comment so you can merge it with your existing `User` class, e.g:
504+
505+
```csharp
506+
/* merge with User DTO
507+
/// <summary>
508+
/// Interface defining the structure for a JobApplication.
509+
/// Represents a user's application to a specific job.
510+
/// </summary>
511+
public class User
512+
{
513+
[AutoIncrement]
514+
public int Id { get; set; }
515+
public string FirstName { get; set; }
516+
public string LastName { get; set; }
517+
public string Email { get; set; }
518+
/// <summary>
519+
/// Optional URL to the user's resume
520+
/// </summary>
521+
public string? ResumeUrl { get; set; }
522+
}
523+
*/
524+
```
525+
526+
If you wish to add additional properties, you'll first need to add it your `ApplicationUser` class, e.g:
527+
528+
```csharp
529+
public class ApplicationUser : IdentityUser
530+
{
531+
public string? FirstName { get; set; }
532+
public string? LastName { get; set; }
533+
public string? DisplayName { get; set; }
534+
public string? ProfileUrl { get; set; }
535+
/// <summary>
536+
/// Optional URL to the user's resume
537+
/// </summary>
538+
public string? ResumeUrl { get; set; }
539+
}
540+
```
541+
542+
You'll then need to regenerate the EF Migration to update the `AspNetUsers` table with the new columns by
543+
running the `init-ef` npm script:
544+
545+
:::sh
546+
npm run init-ef
547+
:::
548+
549+
Which will delete the existing Migrations and create a new Migration to update the Identity Auth tables:
550+
551+
```json
552+
{
553+
"scripts": {
554+
"init-ef": "node -e 'fs.readdirSync(`Migrations`).filter(x => !x.startsWith(`Migration`)).forEach(x => fs.rmSync(`Migrations/${x}`))' && dotnet ef migrations add CreateIdentitySchema",
555+
}
556+
}
557+
```
558+
559+
You can then delete your Primary Database (e.g. App_Data/app.db) and re-run the `migrate` npm script to recreate it:
560+
561+
:::sh
562+
npm run migrate
563+
:::
564+
565+
If you want the additional property to be included in API Responses you'll also need to add it to your `User` DTO, e.g:
566+
567+
```csharp
568+
/// <summary>
569+
/// Public User DTO
570+
/// </summary>
571+
[Alias("AspNetUsers")]
572+
public class User
573+
{
574+
public string Id { get; set; }
575+
public string UserName { get; set; }
576+
public string? FirstName { get; set; }
577+
public string? LastName { get; set; }
578+
public string? DisplayName { get; set; }
579+
public string? ProfileUrl { get; set; }
580+
public string? ResumeUrl { get; set; }
581+
}
582+
```
583+
584+
Which OrmLite and AutoQuery will use to query Identity Auth's `AspNetUsers` table.
585+
499586
### Custom APIs
500587

501588
When you need more fine-grained control over the generated APIs, you can "takeover" the generation of

0 commit comments

Comments
 (0)