I miei modelli EF simile a questa:ASP.NET Entity Framework 6 HashSet o Elenco per una raccolta?
public class ContentStatus
{
public ContentStatus()
{
this.Contents = new List<Content>();
}
public int ContentStatusId { get; set; }
public string Name { get; set; }
public virtual ICollection<Content> Contents { get; set; }
}
implementatins Tuttavia ho anche visto simile a questo:
public class ContentStatus
{
public ContentStatus()
{
this.Contents = new HashSet<Content>();
}
public int ContentStatusId { get; set; }
public string Name { get; set; }
public virtual ICollection<Content> Contents { get; set; }
}
Ecco il DDL per questo oggetto:
CREATE TABLE [dbo].[ContentStatus] (
[ContentStatusId] INT NOT NULL,
[Name] NVARCHAR (50) NOT NULL,
CONSTRAINT [PK_ContentStatus] PRIMARY KEY CLUSTERED ([ContentStatusId] ASC)
);
Can
chiunque dimmi che dovrei usare o anche se c'è una differenza e quando dovrei usare la lista e quando Hashset se questo si applica.
Grazie
'HashSet' può essere ripetuto. Qualsiasi classe che implementa 'IEnumerable' può, ed entrambi' Lista 'e' HashSet 'la implementano. –
@XavierPoinas risposta aggiornata ... dio sa da dove ho avuto quell'idea da ... –
Suppongo che Hashset sarebbe più costoso per gli inserti, dal momento che assicura l'unicità e quindi deve essere confrontato con altre voci o almeno con gli hash, ma meno costoso per la rimozione (supponendo che un hash trovi gli oggetti più velocemente di quanto farebbe l'elenco di enumerazione). –