markrendle / Simple.Data

A light-weight, dynamic data access component for C# 4.0
MIT License
1.33k stars 302 forks source link

Singular name in one-to-many relationship #311

Open pako1337 opened 11 years ago

pako1337 commented 11 years ago

Hi, I've stumbled upon one following issue: I have two tables connected in one to many relationship. This is ContentElement and Language - Content can have one Language, Language can be assigned to many ContentElements. The relationship I'm interested in is from Content to Language. In database, tables are named ContentElements and Languages to make it sound a bit better when making queries.

ContentElements:
ContentElementId: int, serial
DefaultLanguage: varchar(10)

Languages:
LanguageId: varchar(10)
Name: varchar(255)

Classes:

public class ContentElement
{
    public int ContentElementId {get;set;}
    public Language Language {get;set;}
}
public class Language
{
    public string LanguageId {get;set;}
    public string Name {get;set;}
}

With this, I can do query:

List<ContentElement> e = db.ContentElements.All().WithLanguages();

But it won't populate Language property with instance of an object. However, if I will rename it to Languages then it will.

I'm using Simple.Data v. 0.18.3.1 with Simple.Data.PostgreSql - latest version from github (unfortunately not available as NuGet package, author seems to handle it with some delay).

Is this problem from using PostgreSql? Is there any way I can work around this issue simply? Having single-element property with plural name seems dirty. Ideally I would like to name this property DefaultLanguage but that's the trade off I'm willing to accept to have some fun with this pretty awesome library.