Repository pattern and localized lookup tables

Viewed 3334

I am trying to grabs the idea of the pattern repository and trying to get it implemented in database structures I've already set up in the past. I'm now trying to get the best practice to work with my lookup tables. I've created a test project to play around and this is my database model:

enter image description here

You can see that I have three tables for the lookups: Lookup, Language and LookupLanguage. Language table simply contains the languages.

enter image description here

Lookup tables holds the different types used throughout the models. enter image description here

And LookupLanguage links the both tables together: enter image description here

I've created anew project with all the models 1 to 1 to the database tables: enter image description here

I also created a generic repository and a generic CrudService interface:

public interface ICrudService<T> where T : IsActiveEntity, new()
{
    int Create(T item);
    void Save();
    void Delete(int id);
    T Get(int id);
    IEnumerable<T> GetAll();
    IEnumerable<T> Where(Expression<Func<T, bool>> func, bool showDeleted = false);
    void Restore(int id);
}

Now, according to the following post: When implementing the repository pattern should lookup value / tables get their own Repository? , the repository should hide the underlying database layer. So I think I need a new implementation of a service and/or repository to get the lookups, but then, where do I have to tell in which language I need to have the lookup?

Let's take the status (new, accepted, refused) from the company as an example.

The company model is as follow:

public partial class Company : IsActiveEntity
{
    [Required]
    [MaxLength(50)]
    public string CompanyName { get; set; }
    public System.Guid StatusGuid { get; set; }

    [ForeignKey("StatusGuid")]
    public virtual Lookup Status { get; set; }
}

I guess I don't need to have a separate implementation of a repository? But I need a separate implementation CompanyService.

interface ICompanyService : ICrudService<Company>
{
    IQueryable<LookupLanguage> GetStatuses(Guid languageguid);
    LookupLanguage GetStatus(Guid statusguid, Guid languageguid);
}

Is this the correct approach, or do I miss something here?

5 Answers
Related