Error using Merge in Servicestack.OrmLite Sql Server

206 views Asked by At

Using the latest version of https://github.com/ServiceStack/ServiceStack.OrmLite

[Schema("dbo")]
[Alias("ShelvingCount")]
public class ShelvingCount: IHasId<int>    
{
    [Alias("ShelvingCountId")]
    [Index(Unique = true)]
    [AutoIncrement]
    public int Id { get; set;}

    [Required]
    [References(typeof(Account))]
    public int AccountId { get; set; }
    [Reference]
    public Account Account { get; set; }

    [Required]
    public DateTime Date { get; set; }

    [Required]
    public int Quantity { get; set; }

    [Required]
    public int? Status { get; set; }
}

I removed the property EmployeeId which was a foreigh key to the Employees table. And I forgot to remove the "Merge command" in the code below:

var result = await dbCon.SqlListAsync<ShelvingCount>("EXEC getAllShelvingCounts @accountId, @status, @fromDate, @toDate", new { accountId, status, fromDate, toDate });

// Load the references
var employees = dbCon.Select<Employee>();
result.Merge(employees);

return result;

Then it resulted in the error below. I know that I should have removed the merge command. However, it can be fixed by ignoring the Merge command in cases when there is no reference to that table.

{ResponseStatus:{ErrorCode:Exception,Message:Could not find Child Reference for 'Employee' on Parent 'ShelvingCount',StackTrace:"[AllShelvingCounts: 24/06/2015 4:15:01 AM]:
[REQUEST: {AccountId:0,Status:-1,FromDate:2015-06-22,ToDate:2015-06-24}]
System.Exception: Could not find Child Reference for 'Employee' on Parent 'ShelvingCount'
   at ServiceStack.OrmLite.OrmLiteUtils.Merge[Parent,Child](List`1 parents, List`1 children)
   at Next.Management.Repository.ShelvingCountRepository.<GetAllShelvingCounts>d__0.MoveNext() in c:\dev\Next\Logistics\Management\src\Management.Repository\Repository\ShelvingCountRepository.cs:line 26

Is it some relevant issue to be fixed?

Taking into account that the exception might help the developer to remove the useless merge command, It might be interesting to alert the servicestack developers.

1

There are 1 answers

0
mythz On BEST ANSWER

This is working as intended, the error message indicates that it couldn't find a static relationship that could be merged which negates the purpose of the Merge command - to merge related result sets. When there is no statically defined relationship that exists, this is clearly an error the developer should know about since their usage of the API is not working as intended.

This is the same as setting a non-existent/misspelt property in a statically typed language, i.e. the Compiler feedback is there to catch developer errors.