Specifies that the class in question is a complex type, used for the construction of several other Models .
For example:
[ComplexType]
public class Address
{
[Key]
public int AddressId { get; set; }
public string Street { get; set; }
public string City { get; set; }
public string PostalCode { get; set; }
}
public class Person
{
[Key]
public int PersonId { get; set; }
...
public Address Address { get; set; }
}
public class Company
{
[Key]
public int CompanyId { get; set; }
...
public Address Address { get; set; }
}
A ComplexType
can not normally be accessed directly by a data context.
It serves to explicitly indicate a relation N to 1. It is indicated when the name of the property is not standard.
For example:
public class Movimentacao
{
[Key]
public int MovimentacaoId { get; set; }
public int ProdutoId { get; set; }
public int UsuarioId { get; set; }
[InverseProperty("UsuariosMovimentaramProdutos")]
public virtual Produto Produto { get; set; }
[InverseProperty("UsuariosMovimentaramProdutos")]
public virtual Usuario Usuario { get; set; }
}
public class Usuario
{
[Key]
public int UsuarioId { get; set; }
...
public virtual ICollection<Movimentacao> UsuariosMovimentaramProdutos { get; set; }
}
public class Produto
{
[Key]
public int ProdutoId { get; set; }
...
public virtual ICollection<Movimentacao> UsuariosMovimentaramProdutos { get; set; }
}
Explicitly indicates which foreign entity the foreign key property refers to. For example:
public class Usuario
{
[Key]
public int UsuarioId { get; set; }
...
public virtual ICollection<Movimentacao> UsuariosMovimentaramProdutos { get; set; }
}
public class Produto
{
[Key]
public int ProdutoId { get; set; }
[ForeignKey("Usuario")]
public OperadorDeCadastroId { get; set; }
...
public virtual ICollection<Movimentacao> Movimentacoes { get; set; }
public virtual Usuario OperadorDeCadastro { get; set; }
}
Indicates to the Scaffolding engine whether or not the column should be generated in your View .
Usually used to not put the property in View .