Unfortunately this query throws because of “Ambiguous column” exceptions. I thought that by adding the anonymous parameters in the left join in enough for the aliasing?
The Cart and Items objects are simple pocos as I don’t like putting ServiceStack attributes on those common that are shared between projects. Instead, I have two mappings like those:
public class ContactMapping : OrmLiteMapping<Contact>
{
public ContactMapping()
{
MapToTable("contacts");
MapToSchema("something");
MapToColumn(p => p.Name, "name");
MapToColumn(p => p.UserId, "user_id");
MapToColumn(p => p.ContactId, "contact_id");
}
}
public class Contact
{
public Guid UserId { get; set; }
public Guid ContactId { get; set; }
public String Name { get; set; }
}
The Items class is:
public class Items
{
public int ItemsId { get; set; }
public Guid UserId { get;set; }
public Guid ContactId { get;set; }
public DateTime? CompletedOn { get;set; }
}
The OrmLiteMapping class is just a set of convenience methods to achieve the same effect as adding the necessary attributes on the POCO objects.
public abstract class OrmLiteMapping<TEntity> : IOrmLiteMapping
{
protected void Ignore(Expression<Func<TEntity, object>> expression)
{
var info = (PropertyInfo)ReflectionHelper.GetMemberInfo(expression);
info.AddAttributes(new IgnoreAttribute());
}
protected void AutoIncrement(Expression<Func<TEntity, object>> expression)
{
var info = (PropertyInfo)ReflectionHelper.GetMemberInfo(expression);
info.AddAttributes(new AutoIncrementAttribute());
}
protected void MapToColumn(Expression<Func<TEntity, object>> expression, String columnName)
{
var info = (PropertyInfo)ReflectionHelper.GetMemberInfo(expression);
info.AddAttributes(new AliasAttribute(columnName));
}
protected void MapToTable(String tableName)
{
typeof(TEntity).AddAttributes(new AliasAttribute(tableName));
}
protected void MapToSchema(String schema)
{
typeof(TEntity).AddAttributes(new SchemaAttribute(schema));
}
}
The error I m getting after running the query above is:
Result Message:
System.AggregateException : One or more errors occurred.
----> System.Data.SqlClient.SqlException : Ambiguous column name 'user_id'.
Ambiguous column name 'contact_id'.
The service stack version I m using is 4.5.4
You are correct about the missing select but thats not the problem in this case
Actually you know what? I just added the missing select at the end and it just worked! I didnt expect that ServiceStack would throw this message with the missing select! Thanks for your help!