zzz projects Entity Framework Core EF Core
Home Articles Knowledge Base Online Examples
  • Home
  • Articles
  • Knowledge Base
  • Online Examples

Entity Framework Core - Knowledge Base (KB)

20 results in tag: data-annotations

Entity framework data annotation of foreign key without a navigation property

I have the following table definition:...public partial class ClientClassification { [Key, Column(Order = 0)] public long ClientId { get; set; } [Key, Column(Order = 1)] public ClientClassificationEnum ClientClassificationType { get; set;...
c# data-annotations entity-framework entity-framework-6 foreign-keys
asked by TheEdge

How to specify Unique Key in EF 7 Code First with Data Annotations

You can specified a Unique Key with Fluent Api:...public class MyContext : DbContext { public DbSet<User> Users { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<User>() ...
code-first data-annotations entity-framework entity-framework-core
asked by Ruben Perez

In Entity Framework 7 which property Attribute creates an index in code first?

In Entity Framework 7 (7.0.0-rc1-final) which property Attribute creates an index?...I would normally add an index to a sql table to improve look up times so I assume I need to specify this in my class?...public class Account { [Key] [Required] publ...
data-annotations entity-framework-core
asked by Petras

Does EF Core SaveChanges validate against the data annotations

I have a model with Data Annotations and I was wondering if it was possible to have the SaveChanges method fail if the Data Annotation failed?...I was expecting SaveChanges to throw an exception along the lines of "Test2 is outside the Range of 2 to 4". ...
c# data-annotations entity-framework-core
asked by VorSiechtIP

Entity Framework 6 creates Id column even though other primary key is defined

I defined a DataObject as:...public class SensorType : EntityData { //PKs public string CompanyId { get; set; } public string ServiceId { get; set; } public string Type { get; set; } } ...And used fluent API to make CompanyId and ServiceI...
c# data-annotations ef-fluent-api entity-framework entity-framework-6
asked by Emil Nyborg

Validating entities using data annotations or fluent api in EF 7.0 (In Memory)

I can't verify and test my database by in memory providers. for example I set these properties to required : ...public abstract class Log { #region Properties public Guid Id { get; set; } [Required] public string ClientIp { get; set; } ...
data-annotations entity-framework-core in-memory-database mstest unit-testing
asked by paradise_human

Entity Framework Core Data Annotation Database Generated Values

The Entity Framework Core documentation for ...Generated Properties... makes it seem like Data Annotations can be used for generated code first ..."timestamp"... properties such as created/updated on as a ...DateTime... type....When trying to use the foll...
c# data-annotations entity-framework-core sql-server
asked by Alexander Staroselsky

Mapping composite foreign key to composite primary key where the foreign key is also a primary key

I want to make VM_hostname,datetime and name properties as a composite Key for ...Disk class... . At the same time VM_hostname and datetime of ...Disk class... should refer to VM_hostname and datetime of ...VirtualMachine... class (ie Foreign keys) . ...I...
data-annotations entity-framework entity-framework-6
asked by NeuralLynx

EntityFramework Core auto generate key id property

Using .Net Core MVC. I need to setup my model so that EntityFrameworkCore will auto generate the ID property. I thought that just adding the ...[Key]... annotation would do this, but it doesn't. As a matter of fact, it produces an error when the ID fie...
asp.net-core asp.net-core-mvc c# data-annotations entity-framework-core
asked by Joe Higley

EF Core one to many to many to one relationship

I've worked with databases for a long time now but am new to Entity Framework. I handle both the aspects of programming and database development. As a db developer, I try to keep it clean so this structure that I came up with works well for me but I'm not...
data-annotations ef-fluent-api entity-framework-core relationships
asked by Tony Phan

Does the Required attribute have any effect on a navigation property?

I have the following code in an EF data model:...[Required] public IdentityTypeDocument IdentityType { get; set; } [Required] [ForeignKey(nameof(IdentityType))] public int? IdentityTypeId { get; set; } ...Does the first ...Required... - on the ...Identit...
c# data-annotations entity-framework entity-framework-6
asked by ProfK

asp.net core model four decimal places validation

In my model in asp.net core when I scaffold my database it only allows for a number with two decimal places like 0.10 but, I am not allowed to insert four decimal places into my database....Below is my model.... public class Order { public int Ord...
asp.net-core asp.net-core-2.0 c# data-annotations entity-framework-core
asked by Alex Zimmerman

how to change type validation error messages?

I'm using entity framework code first in an ASP MVC project, and I'd like to change the error message that appears for validation of a numeric type....I have a property like...public decimal Amount1 { get; set; } ...If I enter a non-number in the field, I...
c# data-annotations entity-framework entity-framework-6 validation
asked by Mike

Can't set primary key and foreign key on one column

So I try to create some ASP.NET project with EF Core....I want to set propert of one entity as primary key and foreign key to another entity. The relationship is ...0..1 - 1.... I use ...DataAnnotations...:...public class OfficeAssignment { [Key, Fore...
c# data-annotations entity-framework-core
asked by Michał Turczyn

Entity Framework Core, DELETE CASCADE, and [Required]

I am running into an issue DELETE CASCADE in Entity Framework Core that I can't seem to find a good solution to....Here's a super simplified version of my model:...User {UserID, Name} Recipe {RecipeID, UserID} Ingredient {IngredientID, UserID} RecipeIngre...
asp.net-mvc c# data-annotations entity-framework-core
asked by ChadSC

How do I generate a primary key that is not random?

I want to be able to set the value of my primary key to an auto increment number. At the moment it generates a random key such as 13917c50-6b8c-4405-82ce......I want to be able to tell the system "Hey, I want request number to start at 1 (or 1000 or whate...
c# data-annotations entity-framework-core
asked by Chad Lomax

Writing Range Data Annotation with Fluent API in Entity Framework Core

Description...As I'm trying to adopt ...Clean Architecture..., I want to move away from ...Data Annotations... and use ...Fluent API... which, personally, I started to prefer a lot more....However, I'm not too skilled in this way of implementing things...
asp.net-core c# clean-architecture data-annotations entity-framework-core
asked by Daniel Simionescu

RegEx for specific extension validation

I'm trying to validate upload file extensions on client side (razor) with DataAnnotations, however it looks like no matter what file I'm uploading I always get the "Error Message",... [RegularExpression(@"^.*\.(jpg | JPG | gif | docx | doc | DOC | pdf | P...
asp.net-core-mvc c# data-annotations entity-framework-core regex
asked by Assaf Our

Why some of my Data Annotations in my dto class are not working when I validate the Model in my WebApi?

I have Dto class with data annotations on my properties, but one of them is getting ignored when ModelValidation is performed:...Dto Class:...public class TestClassDto { [Required()] //This one is getting ignored! public virtual System.Guid Id { get; se...
asp.net-mvc asp.net-web-api c# data-annotations entity-framework-core
asked by Victor

ASP.NET Core 3 remote validation with EF Core 3

Bit of an EF beginner's question really, but I'm running into a problem using the [Remote] validation using ASP.NET MVC Core 3 with EF Core 3....Following one of Microsoft's posts, it suggested keeping everything "DRY" (don't repeat yourself). So as dire...
asp.net-core-mvc asp.net-mvc data-annotations entity-framework entity-framework-core
asked by DrGriff

Page 1 of 1
  • 1

Prime Library

Performance

  • Entity Framework Extensions
  • Entity Framework Classic
  • Bulk Operations
  • Dapper Plus

Expression Evaluator

  • C# Eval Expression
  • SQL Eval Function
More Projects...

Related

  • EF Extensions Online Benchmark
  • WIN an EF Extensions license
  • EF6 BatchSaveChanges for only $79
Get monthly updates by subscribing to our newsletter!
SUBSCRIBE!