Since I prefer attributes, here the alternative for the sake of completeness:
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int Id { get; set; }
Note: This works also in EF Core.
More Related Contents:
- Entity Framework Timeouts
- Read SQL Table into C# DataTable
- Dynamically change connection string in Asp.Net Core
- Pass table valued parameter using ADO.NET
- Can I reuse code for selecting a custom DTO object for a child property with EF Core?
- LINQ to SQL multiple tables left outer join
- DropdownList DataSource
- The instance of entity type cannot be tracked because another instance of this type with the same key is already being tracked
- The result of a query cannot be enumerated more than once
- Entity Framework – retrieve ID before ‘SaveChanges’ inside a transaction
- Stop SQL query execution from .net Code
- Entity Framework. Delete all rows in table
- “The LINQ expression node type ‘Invoke’ is not supported in LINQ to Entities” – stumped!
- EF 6 Parameter Sniffing
- Retrieve an object from entityframework without ONE field
- Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.0.0
- Anonymous type result from sql query execution entity framework
- What is passing parameters to SQL and why do I need it?
- How to make LINQ execute a (SQL) LIKE range search
- The entity type ApplicationUser is not part of the model for the current context
- User in Entity type MVC5 EF6
- Entity framework EF.Functions.Like vs string.Contains
- Entity Framework | Sequence contains more than one matching element
- Index (zero based) must be greater than or equal to zero
- Working with SQL views in Entity Framework Core
- Unable to find the requested .Net Framework Data Provider. It may not be installed
- Database Error: There is no row at position 0
- How to set Identity Seed value in code-first?
- Querying data using Entity Framework from dynamically created table
- Update-Database command is not working in ASP.Net Core / Entity Framework Core because object in database already exists