Ambiguous match found. Error on Dataportal Fetch.

Ambiguous match found. Error on Dataportal Fetch.

Old forum URL: forums.lhotka.net/forums/t/5106.aspx


eloew posted on Wednesday, July 16, 2008

Ambiguous match found. Error on Dataportal Fetch.

The GetParameterTypes method in the MethodCaller does not recognise the DataRow[]. It returns a DataRow only.
It then looks for a method with the same number of parameters, of which I have two so I get the "Ambiguous match found."

My current workaround was to add a extra unused param to the GetIssueComments GetIssueComments(DataRow[] rows) & Child_Fetch(DataRow[] rows).
Is there a better way to get around this problem?


//Code that causes Ambiguous match found. Error
internal static IssueComments GetIssueComments(DataRow[] rows)
{
 return DataPortal.FetchChild<IssueComments>(rows);
}

internal static IssueComments GetIssueComments(DataRowCollection rows)
{
 return DataPortal.FetchChild<IssueComments>(rows);
}


private void Child_Fetch(DataRow[] rows)
{
 ...
}

private void Child_Fetch(System.Data.DataRowCollection rows)
{
 ...
}


//Workaround code
internal static IssueComments GetIssueComments(DataRow[] rows)
{
 return DataPortal.FetchChild<IssueComments>(rows,0);
}

internal static IssueComments GetIssueComments(DataRowCollection rows)
{
 return DataPortal.FetchChild<IssueComments>(rows);
}


private void Child_Fetch(DataRow[] rows, int unused)
{
 ...
}

private void Child_Fetch(System.Data.DataRowCollection rows)
{
 ...
}

RockfordLhotka replied on Thursday, July 17, 2008

That's probably your best workaround right now.

You wouldn't believe how complex it is to dynamically invoke methods when you choose to support the concept of a param array... Well you might if you've ever tried to write that code :)

But it is nuts, because it is difficult (at best) to differentiate between a param array and a regular array. Obviously it can be done, and obviously I haven't yet quite replicated the behavior of the C# and VB compilers in this regard...

I did think I had it figured out - but obviously not - so I'll add this to the wish list as something I'll need to revisit.

eloew replied on Thursday, July 17, 2008

Thanks for the replay, and also thanks for the CSLA & wonderfull books.

decius replied on Thursday, October 06, 2011

Hi Rocky, was this resolved since? I'm experiencing similar problems with a create that has a IEnumerable<byte[]> as its only parameter and can't seem to nail down what's happening.

There's only one DataPortal_Create but I still have an ambiguous match which is confusing. I tried wrapping it in a SingleCriteria value and even adding dummy-like parameters, but no luck.

As a work around, Instead of sending the bytes through the factory method, I think I'll just make the factory method create empty and then add the files after the factory returns the empty new object.But I thought this behavior was odd.

 

 

 

public class ImportFiles : Csla.BusinessListBase<ImportFiles, ImportFile>
    {
#if !SILVERLIGHT
        internal static ImportFiles New(IEnumerable<byte[]> files)
        {
            return Csla.DataPortal.Create<ImportFiles>(files);
        }

#endif
#if SILVERLIGHT
        internal static void New(IEnumerable<byte[]> files, EventHandler<DataPortalResult<ImportFiles>> callback)
        {
            var dp = new DataPortal<ImportFiles>(DataPortal.ProxyModes.LocalOnly);
            dp.CreateCompleted += callback;
            dp.BeginCreate(files);
        }
#endif

#if !SILVERLIGHT
        [RunLocal()]
#endif
        private void DataPortal_Create(IEnumerable<byte[]> files)
        {
            AddRange(
                from x in files
                select ImportFile.New(x));
        }

    }

RockfordLhotka replied on Thursday, October 06, 2011

You are talking about the root data portal, and the original thread was about the child data portal.

Andres provided a solution for the child data portal that is in 4.2, where arrays should now work as expected.

But the rules for the root data portal are different. The criteria parameter you provide to the root data portal is serialized to the server, and so must be a serializable type. This means it must implement IMobileObject if you want to support Silverlight/WP7/WinRT.

The concrete type of your IEnumerable<byte[]> would have to implement IMobileObject - and you can't guarantee that with your code.

I'd suggest using Csla.Core.MobileList as your parameter type - thus allowing a list, but ensuring it is serializable.

Copyright (c) Marimer LLC