./../
  I D :    ¾ÏÈ£ :    IDÀúÀå      ȸ¿ø°¡ÀÔ    ³×°Ô(ÁåÀå) ÂÊÁöº¸³»±â    ¸Þ¸ðÀå    °¢Á¾°è»ê±â    Ä÷¯ºü·¿    À̸ðƼÄÜ(ÇÁ·¹ÀÓ, »õâ)    º¸À¯Àåºñ
¸ñ·ÏÀ¸·Î °¡±â..
Entity Framework : Data Annotations ±èÁ¾È£ | »èÁ¦Çϱâ

Data AnnotationÀº .NET Framework¿¡¼­ Data ValidationÀ» µ½±â À§ÇØ Á¦°øµÇ´Â ±â´ÉÀ¸·Î Ŭ·¡½ºÀÇ ¼Ó¼º¿¡ ¿©·¯ Data Annotation Ư¼º(attribute)¸¦ Ãß°¡ÇÔÀ¸·Î º°µµÀÇ ÄÚµå¾øÀÌ Validation ±ÔÄ¢À» Àû¿ëÇÒ ¼ö ÀÖ´Ù. Entity FrameworkÀÇ DbSet Ŭ·¡½º¿¡¼­ ÀÌ·¯ÇÑ Data AnnotationÀ» »ç¿ëÇÏ¿© Å×À̺í Ä÷³¿¡ Ưº°ÇÑ ¼Ó¼ºÀ» ÁöÁ¤ÇÒ ¼ö ÀÖÀ¸¸ç, ¶ÇÇÑ °¢ ÇʵåÀÇ Ãâ·ÂÆ÷¸Ë°ú Ư¼ºµéÀ» ÁöÁ¤ÇÏ¿© ASP.NET MVC¿Í °°Àº ¿ÜºÎ ÇÁ·¹ÀÓ¿öÅ©¿¡¼­ ÀÌ·¯ÇÑ Validation Ư¼ºµéÀ» È°¿ëÇÒ ¼ö ÀÖµµ·Ï ÇÏ°í ÀÖ´Ù. Entity Framework¿¡¼­ Å×ÀÌºí ½ºÅ°¸¶¸¦ Á¤ÀÇÇϴ Ŭ·¡½º¸¦ ÀÛ¼ºÇÒ ¶§, Ä÷³Å¸ÀÔ, ÃÖ´ë Å©±â, Identity ¼Ó¼º µî Å×À̺í Á¤ÀÇ¿¡ ÇÊ¿äÇÑ ¿©·¯ ¼Ó¼ºµéÀ» ÇÔ²² ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù. ¶ÇÇÑ, Ŭ·¡½ºÀÇ Çʵå(Ä÷³)°¡ ¿ÜºÎ¿¡ Ç¥½ÃµÉ ¶§, DisplayName À̳ª DisplayFormat °°Àº Ư¼ºµéÀ» »ç¿ëÇÒ ¼ö Àִµ¥, ¿¹¸¦ µé¾î MVC À¥ ÇÁ·¹ÀÓ¿öÅ©¿¡¼­ ÀÌ·¯ÇÑ Display Ư¼ºµéÀ» »ç¿ëÇÏ¿© ÇʵåÀÇ Çì´õ³ª Æ÷¸ËÀ» ÀÚµ¿À¸·Î Àû¿ëÇÑ´Ù. ¾Æ·¡ ¿¹Á¦´Â Customer Ŭ·¡½º¿¡ ¿©·¯ Data AnnotationÀ» ºÙ¿©º» »ùÇÃÀÌ´Ù. Entity Framework¿¡¼­ Primary Key (PK)¸¦ ÁöÁ¤Çϱâ À§ÇØ, [Key] ¶ó´Â Ư¼ºÀ» ÁöÁ¤ÇÑ´Ù. ¸¸¾à Ŭ·¡½º¿¡ Key Ư¼ºÀÌ ¾øÀ¸¸é Id ȤÀº *Id¿Í °°ÀÌ ³¡ÀÌ Id·Î ³¡³ª´Â Ä÷³À» Primary Key·Î »ç¿ëÇÑ´Ù. Id Ä÷³Àº Identity ·Î ¸¸µé±â À§Çؼ­´Â DatabaseGenerated(DatabaseGeneratedOption.Identity) Ư¼ºÀ» ÁöÁ¤ÇÏ¸é µÇ´Âµ¥, À̸¦ »ç¿ëÇϸé Id Ä÷³ÀÌ DB¿¡¼­ ÀÚµ¿À¸·Î ä¿öÁø´Ù. PK ÀÌ¿Ü¿¡ Foreign Key¸¦ ÁöÁ¤Çϱâ À§Çؼ­´Â [ForeignKey()] ¸¦ »ç¿ëÇϸç, ƯÁ¤ Ä÷³¿¡ À妽º¸¦ »ý¼ºÇϱâ À§Çؼ­´Â [Index] Ư¼ºÀ» ÁöÁ¤ÇÑ´Ù. Ä÷³ÀÌ ¹Ýµå½Ã µ¥ÀÌŸ°¡ ÀԷµǾî¾ß ÇÏ´Â °æ¿ì Áï NULLÀÌ Çã¿ëµÇÁö ¾Ê´Â °æ¿ì [Required] Ư¼ºÀ» ÁöÁ¤ÇÑ´Ù. ¶ÇÇÑ, ¹®ÀÚ¿­ÀÇ ÃÖ´ë, ÃÖ¼Ò±æÀ̸¦ Ç¥ÇöÇϱâ À§Çؼ­´Â MaxLength(n), MinLength(m) Ư¼ºÀ» ÁöÁ¤ÇÑ´Ù. ¿¹Á¦ using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Data.Entity; public class Customer { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } [StringLength(100)] [Index(IsUnique = true)] public string LoginId { get; set; } [Display(Name = "Create Date")] [DataType(DataType.Date)] [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)] public DateTimeOffset CreateDate { get; set; } [Required] [MaxLength(100)] public string Name { get; set; } [EmailAddress] public string Email { get; set; } public int Age { get; set; } } ÀÚÁÖ »ç¿ëµÇ´Â Data Annotation
Data Annotation¼³¸í¿¹Á¦
Table Table ¼Ó¼º ÁöÁ¤. Table¸í ÁöÁ¤ [Table("CustTab")]
public class Customer
Column Column ¼Ó¼º ÁöÁ¤ [Column("Misc", typename="ntext")]
public string Data {get; set; }
Key Primary Key ÁöÁ¤ [Key] public int Id { get; set; } PK°¡ º¹¼ö Ä÷³ÀÎ °æ¿ì:
[Key] [Column(Order=1)]
public string FirstName { get; set; }
[Key] [Column(Order=2)]
public string Last { get; set; }
ForeignKey Foreign Key [ForeignKey("Id")]
public int EmpId { get; set; }
Index Index Ä÷³ ÁöÁ¤ (EF 6.1+) [Index]
public int RefId { get; set; }
DatabaseGenerated DB »ý¼º ¿É¼Ç ÁöÁ¤ [DatabaseGenerated(DatabaseGenerationOption.Identity]
public int Id { get; set; }
Required Çʼö Ç׸ñ. NOT NULL Çʵå [Required]
public string Name { get; set; }
MaxLength ÃÖ´ë ±æÀÌ [MaxLength(100)]
public string Name { get; set; }
MinLength ÃÖ¼Ò ±æÀÌ [MinLength(5)]
public string Name { get; set; }
Range ÃÖ¼Ò, ÃÖ´ë ¹üÀ§°ªÀ» ÁöÁ¤ [Range(0, 100)]
public int Score { get; set; }
NotMapped Å×ÀÌºí¿¡ ÀúÀåµÇÁö ¾Ê´Â Çʵå [NotMapped]
public int Extra { get; set; }
Timestamp Timestamp Ä÷³ [Timestamp]
public byte[] TimeStamp { get; set; }
Email Email ÁÖ¼Ò Ã¼Å© [EmailAddress]
public string Email { get; set; }


÷¾ð ´Þ±â
À̸§ : ¾ÏÈ£ :
¹øÈ£    Á¦¸ñ...(÷¾ð) ÀÛ¼ºÀÏ Á¢¼Ó
xxx [°øÁö]ÀÚÀ¯°Ö·¯¸® µî·Ï ¿À·ù ¼öÁ¤ ¿Ï·á 2017-12-22 17439
xxx [°øÁö]ÀÚ·á½Ç ´Ù¿î·Îµå ¿À·ù ó¸® 2017-12-01 18073
xxx [°øÁö]ºñ³­, ±¤°í °Ô½Ã¹°À» ½Å°í, Â÷´Ü, »èÁ¦µË´Ï´Ù. 2005-06-26 18239
138 [ÀϹÝ]  Fiio Memory Directory Name 2018-03-29(¸ñ) 2335
137 [ÀϹÝ]  VirtualBox ¾÷±×·¹À̵åÈÄ NtCreateFile ¿¡·¯ 2018-03-12(¿ù) 4583
136 [ÀϹÝ]  SQL Server 2017 ¼³Ä¡ÇÑ PolyBase ¼³Ä¡ µÇÁö ¾ÊÀ»°æ¿ì 2018-03-09(±Ý) 7281
135 [ÀϹÝ]  UltraEdit(¿ïÆ®¶ó¿¡µðÆ®)¿¡¼­ ÇѱÛÀÌ ±úÁú¶§ 2018-03-08(¸ñ) 15451
134 [ÀϹÝ]  mp3tag ÀÌ¿ëÇؼ­ À½¾ÇÈ­ÀÏ ÇÁ·ÎÆÄÀÏ º¯°æÇÒ¶§ 2018-02-25(ÀÏ) 2229
133 [ÀϹÝ]  »ï¼º ½º¸¶Æ®Æù ¼­ºñ½º ¸ðµå ÁøÀÔ 2018-02-23(±Ý) 5659
132 [ÀϹÝ]  LG V30 °ü¸®ÀÚ ¸ðµå ÁøÀÔ 2018-02-23(±Ý) 2959
131 [ÀϹÝ]  À©µµ¿ì10 ½ÃÀÛ¸Þ´º ¸ÔÅëÀ϶§ 2018-02-20(È­) 3209
130 [ÀϹÝ] > Entity Framework : Data Annotations < 2018-01-25(¸ñ) 2930
129 [C#]  C# ºñµ¿±âÀû ÇÁ·Î±×·¥À» À§ÇÑ Å°¿öµå 2018-01-22(¿ù) 2352
128 [ÀϹÝ]  À̽ºÄÉÀÌÇÁ ½ÃÄö½º 2018-01-16(È­) 2188
127 [ÀϹÝ]  ASP.NET CORE MVC¸¦ IIS¿¡ ¿Ã¸®±â À§ÇØ 2018-01-12(±Ý) 2041
126 [ÀϹÝ]  ASP.NET¿¡¼­ »ç¿ëÇÒ ¼ö ÀÖ´Â ±â¼ú 2018-01-08(¿ù) 2187
125 [ÀϹÝ]  MS SQL SERVER ¿ø°Ý Á¢¼Ó ¾ÈµÉ¶§ 2018-01-08(¿ù) 2297
124 [ÀϹÝ]  VirtualBox VT-x is not available. (VERR_VMX_NO_VMX). ¿À·ù¹ß»ýÇÒ¶§ 2018-01-08(¿ù) 2782
123 [ÀϹÝ]  uTorrent À©µµ¿ì ±âº» ¼³Ä¡ °æ·Î 2017-12-30(Åä) 2270
122 [CPP]  ESP8266 A/D Converter Test 2017-12-21(¸ñ) 2403
121 [ÀϹÝ]  Arduino IDEÀÇ ÆùÆ®, Tab Size, Auto Indent º¯°æ 2017-12-19(È­) 3646
120 [CPP]  ESP8266 MAC Address View 2017-12-18(¿ù) 3665
119 [ÀϹÝ]  ASP.NET C# DB Åë½Å 2017-12-14(¸ñ) 2545
°Ë»ö :
Page : ÀÌÀü 1  2  3  4  5  6  7  8  9  10  11  ´ÙÀ½




Copyright 2003-2024 ¨Ï ±èÁ¾È£. All rights reserved. kimjongho.co.kr kimjongho.kr kimjongho.net kimjongho.com