2012-05-13 35 views

Trả lời

115

Thêm thuộc tính [System.ComponentModel.DataAnnotations.Schema.NotMapped] vào thuộc tính.

+0

Điều này có lợi ích (trên khai báo thông thạo) rằng các thuộc tính được chú thích sẽ (hoặc nên) bị bỏ qua bởi những người lập bản đồ/serializers dữ liệu khác, chẳng hạn như serializers JSON? –

39

mỗi sự accepted answersimilar question/answer, ngoài [NotMapped] bạn cũng có thể xác định nó bằng cách sử dụng API thạo:

protected override void OnModelCreating(DbModelBuilder modelBuilder) 
{ 
    modelBuilder.Entity<TheModelAffected>().Ignore(t => t.TheIgnoredProperty); 
    base.OnModelCreating(modelBuilder); 
} 
12

[NotMapped] là phiên bản ngắn nếu bạn thích conciseness. Và tất nhiên, bạn sẽ thêm:

using System.ComponentModel.DataAnnotations.Schema; 

vào lớp học của bạn.

Các vấn đề liên quan