Cannot implicitly convert type Linq to SQL sproc result RRS feed

  • Question

  • Have an existing sproc:

    CREATE PROCEDURE [dbo].[GetClientDetails] (@theNumber varchar(20))


    SELECT distinct x.*, z.StatusFullDesc, w.orgdesc
    FROM Client x, ClientStatusCodes z, ClientOrgType w
    WHERE (x.Clientnumber =  @theNumber)
    and (x.STATUS = z.Statuscode)
    and (x.ORGTYPE = w.orgcode)


    drag-n-drop onto DataClass.dbml creates:

    public ISingleResult<Phoenix.BEL.GetClientDetailsResult> GetClientDetails([Parameter(DbType="VarChar(20)")] string theNumber)
        IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), theNumber);
        return ((ISingleResult<Phoenix.BEL.GetClientDetailsResult>)(result.ReturnValue));


    created a data adapter class:

    public class ClientAdapter
     public static Client AllClientDetails(string Clientnumber)
       using (DataClassesDataContext db = new DataClassesDataContext())
         var returnClient = db.GetClientDetails(Clientnumber).Single<GetClientDetailsResult>();
         return returnClient;



    Test Console:

    Console.WriteLine("Enter Clientnumber");
    string input =  Console.ReadLine();
    Client client = ClientAdapter.AllClientDetails(input);


    The "return returnBuilder;" gives the error:

    Cannot implicitly convert type 'Phoenix.BEL.GetClientDetailsResult' to 'Phoenix.BEL.Client'

    This is to return 1 result/record.

    Tried many different scenarios.

    Need help to clarify this error.


    Sunday, March 7, 2010 12:42 AM


All replies

  • Stored proc results are a completely different type.  You will need to convert your result object from the proc to the type that you are expecting.  For example:

    var returnClient = db.GetClientDetails(Clientnumber).Single<GetClientDetailsResult>();
    return new Client() {NAME = returnClient.Name};

    Mike Huguet
    • Proposed as answer by Mike Huguet Sunday, March 7, 2010 3:00 AM
    • Marked as answer by trailman Sunday, March 7, 2010 12:14 PM
    Sunday, March 7, 2010 2:52 AM
  • Thanks for clearing that up for me Mike.  This is my first go-around with this technology.

    I did run into another problem though...

    System.FormatException was unhandled Message="String must be exactly one character long."

    I read an article that explained to change any field that is defined as "char" to "string". This doesn't appear to be the issue though. Then I cam across this article [ ].  Can anyone verify this as fact?  I need to modify all of my tables data just to use Linq?
    Sunday, March 7, 2010 12:17 PM
  • Just answered my own question.  See article:

    Linq and Empty String

    Sunday, March 7, 2010 1:47 PM