markrendle / Simple.Data

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

homogenizing not working as expected when column names contain underscores #346

Open rogersillito opened 10 years ago

rogersillito commented 10 years ago

I am working with a SQL Server db where a table is defined as:

CREATE TABLE [dbo].[person]
(
[personnel_number] [int] NULL,
[initials] [nvarchar] (15) COLLATE Latin1_General_CI_AS NULL,
[first_name] [nvarchar] (50) COLLATE Latin1_General_CI_AS NULL,
[last_name] [nvarchar] (50) COLLATE Latin1_General_CI_AS NULL,
[known_as] [nvarchar] (50) COLLATE Latin1_General_CI_AS NULL
// etc...
) ON [PRIMARY]

If I try:

db.dbo.person.FindAllBy(lastname: "Smith");

I get "UnresolvableObjectException: Column 'lastname' not found."

Similarly, if I try to cast the result of an All() query to the following type:

public class Person
{
   public int PersonnelNumber { get; set; }
   public string Initials { get; set; }
   public string FirstName { get; set; }
   public string LastName { get; set; }
   public string KnownAs { get; set; }
}
IEnumerable<Person> result = db.dbo.person.All();

then only Initials and FirstName properties of result get mapped from the results (given what I am seeing, that FirstName should be mapped makes no sense). If I do this instead, all fields are mapped as expected:

public class PersonUnderscore
{
   public int Personnel_Number { get; set; }
   public string Initials { get; set; }
   public string First_Name { get; set; }
   public string Last_Name { get; set; }
   public string Known_As { get; set; }
}
IEnumerable<PersonUnderscore> result2 = db.dbo.person.All();

I have also tried calling this first but it makes no difference:

Simple.Data.Extensions.HomogenizeEx.SetRegularExpression(new Regex("[^a-z0-9]"));