使用Entity Framework,如何才能使SQL表列名只属于该表,即没有外键约束?
这是我的模特:
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public Nullable<byte> Age { get; set; }
public string Address { get; set; }
public string Gender { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<EmployeeQualification> EmployeeQualifications { get; set; }
我使用下面的代码片段来获取列名,但它返回了Model
中的所有属性var names = typeof(EmployeeMaster).GetProperties()
.Select(property => property.Name)
.ToArray();
答案 0 :(得分:1)
试试这个:
var names = typeof(EmployeeMaster).GetProperties()
.Where(x => x.PropertyType.IsValueType || x.PropertyType == typeof(string))
.Select(property => property.Name)
.ToArray();