dotnet / dotnet/EntityFramework.Docs

Document how key configuration and property configuration interact

Open
#1,642 0 comments 0 reactions 0 assignees View on GitHub
area-entity-mapping
Dominant language
Mermaid
Stars
1.7k
Forks
2k
Avg merge
7d 23h
Merged PRs (30d)
16

Description

How about specifying the primary key that has a different SQL column name than my property name?

I believe the following works:

```csharp
modelBuilder.Entity()
.HasKey(myEntity => myEntity.MyId);

modelBuilder.Entity()
.Property(p => p.MyId)
.HasColumnName("MyCustomColumnNameId");
```

I'm happy to update the docs with that pending confirmation it would be accepted?

Reference: https://stackoverflow.com/a/48155599/185123

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: d0a084df-15c4-ab25-26ca-83c8bdf6f026
* Version Independent ID: f1fba5b2-eb2e-da0a-fce0-d492855c1777
* Content: [Keys (primary) - EF Core](https://docs.microsoft.com/en-us/ef/core/modeling/keys)
* Content Source: [entity-framework/core/modeling/keys.md](https://github.com/aspnet/EntityFramework.Docs/blob/master/entity-framework/core/modeling/keys.md)
* Product: **entity-framework**
* Technology: **entity-framework-core**
* GitHub Login: @rowanmiller
* Microsoft Alias: **divega**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.