Created
June 11, 2021 03:43
-
-
Save robsonfaxas/0f6e3dd443879acd7a99c28963903cfc to your computer and use it in GitHub Desktop.
[LinqToSql - Mapeamento entre entidades] Como fazer o mapeamento entre entidades com #linq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
No LinqToSql, para mapear um relacionamento entre entidades, vamos usar o exemplo do relacionamento Category e SubCategory. | |
/*########################################################*/ | |
1 - A subcategory que contém a chave estrangeira, deve conter um objeto "EntityRef<ProductCategory>" privado para ser armazenado a referência e um "Association" public, cujos Get e Set do Association apontam para o EntityRef. | |
/*########################################################*/ | |
private EntityRef<ProductCategory> _ProductCategory; | |
[Association(Storage = "_ProductCategory", ThisKey = "ProductCategoryID", IsForeignKey = true)] | |
public ProductCategory ProductCategory | |
{ | |
get { return this._ProductCategory.Entity; } | |
set { this._ProductCategory.Entity = value; } | |
} | |
/*########################################################*/ | |
2 - A Category precisa informar um EntitySet que é a coleção de SubCategory | |
/*########################################################*/ | |
[Association(OtherKey = "ProductCategoryID")] | |
public EntitySet<ProductSubcategory> ProductSubcategories { get; set; } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment