LINQ to SQL insert-si-inexistante

Je voudrais savoir si il y a un moyen plus simple d'insérer un enregistrement si elle n'existe pas déjà dans une table. Je suis toujours en train de construire mon LINQ to SQL compétences.

Voici ce que j'ai, mais il semble qu'il devrait y avoir un moyen plus facile.

public static TEntity InsertIfNotExists<TEntity>
(
    DataContext db,
    Table<TEntity> table,
    Func<TEntity,bool> where,
    TEntity record
)
    where TEntity : class
{
    TEntity existing = table.SingleOrDefault<TEntity>(where);

    if (existing != null)
    {
        return existing; 
    }
    else
    {
        table.InsertOnSubmit(record);

        //Can't use table.Context.SubmitChanges()
        //'cause it's read-only

        db.SubmitChanges();
    }

    return record;
}
InformationsquelleAutor core | 2008-09-19