Cannot Implicitly convert type 'System.collections.generic.IEnumerable'to'string'












-1















I hava a class and controller as below



 //class
public class Payment
{
public Guid ID { get; set; }
public string InvoiceNumber { get; set; }
public string ContactNumber { get; set; }
public string ConsumerName { get; set; }
}

//controller
public class TransPaymentController : Controller
{

public ActionResult Searching(int? page,string searchInvoiceNumber)
{

//Page Setting
int pageSize = 10;
int pageNumber = (page ?? 1);

IPagedList<Payment> payments = null;
payments= paymentRepo.GetList_Payments_InTableManualPayment(pageSize, pageNumber);


if (!String.IsNullOrEmpty(searchInvoiceNumber))
{

string data = payments.Where(s => s.InvoiceNumber.Contains(searchInvoiceNumber)); //the error is here

}
return null;
}
}


and I get an error as below.



Cannot Implicitly convert type System.collections.generic.IEnumerable<Project.Dto.PaymentDto> to string



why am I getting this error?










share|improve this question




















  • 4





    you declared data as string. The Where does not return a string. What are you actually trying to get? This may be an XY problem.

    – Nkosi
    Jan 20 at 14:01













  • As @Nkosi mentioned, Where would return an IEnumerable in your case. You can convert/project the source data type to target by using a projection like Select or Aggregate (Aggregate can join each item into a single string, and also there is an example on doing that in the documentation docs.microsoft.com/en-us/dotnet/api/…) methods defined in LINQ.

    – Deniz
    Jan 20 at 14:18








  • 1





    If you replace string data by var data your error should disappear. But as the previous comments stated, it is unclear what you are trying to achieve here.

    – Sergioet
    Jan 20 at 16:01













  • @Nkosi Even if this is an XY problem, the Y in this case is fairly fundamental to any prospective solutions to X.

    – Khyron
    Jan 21 at 4:21











  • With basic understanding of the C# language it should be obvious why you get the error. So I'm voting unclear what you are asking, as explaining why will likely not solve your problem.

    – nvoigt
    Jan 21 at 8:30
















-1















I hava a class and controller as below



 //class
public class Payment
{
public Guid ID { get; set; }
public string InvoiceNumber { get; set; }
public string ContactNumber { get; set; }
public string ConsumerName { get; set; }
}

//controller
public class TransPaymentController : Controller
{

public ActionResult Searching(int? page,string searchInvoiceNumber)
{

//Page Setting
int pageSize = 10;
int pageNumber = (page ?? 1);

IPagedList<Payment> payments = null;
payments= paymentRepo.GetList_Payments_InTableManualPayment(pageSize, pageNumber);


if (!String.IsNullOrEmpty(searchInvoiceNumber))
{

string data = payments.Where(s => s.InvoiceNumber.Contains(searchInvoiceNumber)); //the error is here

}
return null;
}
}


and I get an error as below.



Cannot Implicitly convert type System.collections.generic.IEnumerable<Project.Dto.PaymentDto> to string



why am I getting this error?










share|improve this question




















  • 4





    you declared data as string. The Where does not return a string. What are you actually trying to get? This may be an XY problem.

    – Nkosi
    Jan 20 at 14:01













  • As @Nkosi mentioned, Where would return an IEnumerable in your case. You can convert/project the source data type to target by using a projection like Select or Aggregate (Aggregate can join each item into a single string, and also there is an example on doing that in the documentation docs.microsoft.com/en-us/dotnet/api/…) methods defined in LINQ.

    – Deniz
    Jan 20 at 14:18








  • 1





    If you replace string data by var data your error should disappear. But as the previous comments stated, it is unclear what you are trying to achieve here.

    – Sergioet
    Jan 20 at 16:01













  • @Nkosi Even if this is an XY problem, the Y in this case is fairly fundamental to any prospective solutions to X.

    – Khyron
    Jan 21 at 4:21











  • With basic understanding of the C# language it should be obvious why you get the error. So I'm voting unclear what you are asking, as explaining why will likely not solve your problem.

    – nvoigt
    Jan 21 at 8:30














-1












-1








-1


1






I hava a class and controller as below



 //class
public class Payment
{
public Guid ID { get; set; }
public string InvoiceNumber { get; set; }
public string ContactNumber { get; set; }
public string ConsumerName { get; set; }
}

//controller
public class TransPaymentController : Controller
{

public ActionResult Searching(int? page,string searchInvoiceNumber)
{

//Page Setting
int pageSize = 10;
int pageNumber = (page ?? 1);

IPagedList<Payment> payments = null;
payments= paymentRepo.GetList_Payments_InTableManualPayment(pageSize, pageNumber);


if (!String.IsNullOrEmpty(searchInvoiceNumber))
{

string data = payments.Where(s => s.InvoiceNumber.Contains(searchInvoiceNumber)); //the error is here

}
return null;
}
}


and I get an error as below.



Cannot Implicitly convert type System.collections.generic.IEnumerable<Project.Dto.PaymentDto> to string



why am I getting this error?










share|improve this question
















I hava a class and controller as below



 //class
public class Payment
{
public Guid ID { get; set; }
public string InvoiceNumber { get; set; }
public string ContactNumber { get; set; }
public string ConsumerName { get; set; }
}

//controller
public class TransPaymentController : Controller
{

public ActionResult Searching(int? page,string searchInvoiceNumber)
{

//Page Setting
int pageSize = 10;
int pageNumber = (page ?? 1);

IPagedList<Payment> payments = null;
payments= paymentRepo.GetList_Payments_InTableManualPayment(pageSize, pageNumber);


if (!String.IsNullOrEmpty(searchInvoiceNumber))
{

string data = payments.Where(s => s.InvoiceNumber.Contains(searchInvoiceNumber)); //the error is here

}
return null;
}
}


and I get an error as below.



Cannot Implicitly convert type System.collections.generic.IEnumerable<Project.Dto.PaymentDto> to string



why am I getting this error?







c# asp.net-mvc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 21 at 7:46









ArunPratap

2,0162826




2,0162826










asked Jan 20 at 13:58









mithmith

1




1








  • 4





    you declared data as string. The Where does not return a string. What are you actually trying to get? This may be an XY problem.

    – Nkosi
    Jan 20 at 14:01













  • As @Nkosi mentioned, Where would return an IEnumerable in your case. You can convert/project the source data type to target by using a projection like Select or Aggregate (Aggregate can join each item into a single string, and also there is an example on doing that in the documentation docs.microsoft.com/en-us/dotnet/api/…) methods defined in LINQ.

    – Deniz
    Jan 20 at 14:18








  • 1





    If you replace string data by var data your error should disappear. But as the previous comments stated, it is unclear what you are trying to achieve here.

    – Sergioet
    Jan 20 at 16:01













  • @Nkosi Even if this is an XY problem, the Y in this case is fairly fundamental to any prospective solutions to X.

    – Khyron
    Jan 21 at 4:21











  • With basic understanding of the C# language it should be obvious why you get the error. So I'm voting unclear what you are asking, as explaining why will likely not solve your problem.

    – nvoigt
    Jan 21 at 8:30














  • 4





    you declared data as string. The Where does not return a string. What are you actually trying to get? This may be an XY problem.

    – Nkosi
    Jan 20 at 14:01













  • As @Nkosi mentioned, Where would return an IEnumerable in your case. You can convert/project the source data type to target by using a projection like Select or Aggregate (Aggregate can join each item into a single string, and also there is an example on doing that in the documentation docs.microsoft.com/en-us/dotnet/api/…) methods defined in LINQ.

    – Deniz
    Jan 20 at 14:18








  • 1





    If you replace string data by var data your error should disappear. But as the previous comments stated, it is unclear what you are trying to achieve here.

    – Sergioet
    Jan 20 at 16:01













  • @Nkosi Even if this is an XY problem, the Y in this case is fairly fundamental to any prospective solutions to X.

    – Khyron
    Jan 21 at 4:21











  • With basic understanding of the C# language it should be obvious why you get the error. So I'm voting unclear what you are asking, as explaining why will likely not solve your problem.

    – nvoigt
    Jan 21 at 8:30








4




4





you declared data as string. The Where does not return a string. What are you actually trying to get? This may be an XY problem.

– Nkosi
Jan 20 at 14:01







you declared data as string. The Where does not return a string. What are you actually trying to get? This may be an XY problem.

– Nkosi
Jan 20 at 14:01















As @Nkosi mentioned, Where would return an IEnumerable in your case. You can convert/project the source data type to target by using a projection like Select or Aggregate (Aggregate can join each item into a single string, and also there is an example on doing that in the documentation docs.microsoft.com/en-us/dotnet/api/…) methods defined in LINQ.

– Deniz
Jan 20 at 14:18







As @Nkosi mentioned, Where would return an IEnumerable in your case. You can convert/project the source data type to target by using a projection like Select or Aggregate (Aggregate can join each item into a single string, and also there is an example on doing that in the documentation docs.microsoft.com/en-us/dotnet/api/…) methods defined in LINQ.

– Deniz
Jan 20 at 14:18






1




1





If you replace string data by var data your error should disappear. But as the previous comments stated, it is unclear what you are trying to achieve here.

– Sergioet
Jan 20 at 16:01







If you replace string data by var data your error should disappear. But as the previous comments stated, it is unclear what you are trying to achieve here.

– Sergioet
Jan 20 at 16:01















@Nkosi Even if this is an XY problem, the Y in this case is fairly fundamental to any prospective solutions to X.

– Khyron
Jan 21 at 4:21





@Nkosi Even if this is an XY problem, the Y in this case is fairly fundamental to any prospective solutions to X.

– Khyron
Jan 21 at 4:21













With basic understanding of the C# language it should be obvious why you get the error. So I'm voting unclear what you are asking, as explaining why will likely not solve your problem.

– nvoigt
Jan 21 at 8:30





With basic understanding of the C# language it should be obvious why you get the error. So I'm voting unclear what you are asking, as explaining why will likely not solve your problem.

– nvoigt
Jan 21 at 8:30












1 Answer
1






active

oldest

votes


















0














From the look of it, your controller is simply trying to look up an invoice number. The nature of the error relating to converting a collection IEnumerable<Project.Dto.PaymentDto> to a single element string.



Consider what your query is asking the database: Please find me any invoices where the invoice number contains searchInvoiceNumber. The database may return zero, one or many results. What would that look like as a string? That's a nonsense question.



Try instead:



var data = payments.Where(s => s.InvoiceNumber.Contains(searchInvoiceNumber)).ToList();


Now data contains a zero, one or many PaymentDto items. It's up to you to decide what to do with that.



Note that your Payment class isn't being used so far. If you're trying to populate that directly from the query, that's probably a separate question.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54277183%2fcannot-implicitly-convert-type-system-collections-generic-ienumerableproject-d%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    From the look of it, your controller is simply trying to look up an invoice number. The nature of the error relating to converting a collection IEnumerable<Project.Dto.PaymentDto> to a single element string.



    Consider what your query is asking the database: Please find me any invoices where the invoice number contains searchInvoiceNumber. The database may return zero, one or many results. What would that look like as a string? That's a nonsense question.



    Try instead:



    var data = payments.Where(s => s.InvoiceNumber.Contains(searchInvoiceNumber)).ToList();


    Now data contains a zero, one or many PaymentDto items. It's up to you to decide what to do with that.



    Note that your Payment class isn't being used so far. If you're trying to populate that directly from the query, that's probably a separate question.






    share|improve this answer




























      0














      From the look of it, your controller is simply trying to look up an invoice number. The nature of the error relating to converting a collection IEnumerable<Project.Dto.PaymentDto> to a single element string.



      Consider what your query is asking the database: Please find me any invoices where the invoice number contains searchInvoiceNumber. The database may return zero, one or many results. What would that look like as a string? That's a nonsense question.



      Try instead:



      var data = payments.Where(s => s.InvoiceNumber.Contains(searchInvoiceNumber)).ToList();


      Now data contains a zero, one or many PaymentDto items. It's up to you to decide what to do with that.



      Note that your Payment class isn't being used so far. If you're trying to populate that directly from the query, that's probably a separate question.






      share|improve this answer


























        0












        0








        0







        From the look of it, your controller is simply trying to look up an invoice number. The nature of the error relating to converting a collection IEnumerable<Project.Dto.PaymentDto> to a single element string.



        Consider what your query is asking the database: Please find me any invoices where the invoice number contains searchInvoiceNumber. The database may return zero, one or many results. What would that look like as a string? That's a nonsense question.



        Try instead:



        var data = payments.Where(s => s.InvoiceNumber.Contains(searchInvoiceNumber)).ToList();


        Now data contains a zero, one or many PaymentDto items. It's up to you to decide what to do with that.



        Note that your Payment class isn't being used so far. If you're trying to populate that directly from the query, that's probably a separate question.






        share|improve this answer













        From the look of it, your controller is simply trying to look up an invoice number. The nature of the error relating to converting a collection IEnumerable<Project.Dto.PaymentDto> to a single element string.



        Consider what your query is asking the database: Please find me any invoices where the invoice number contains searchInvoiceNumber. The database may return zero, one or many results. What would that look like as a string? That's a nonsense question.



        Try instead:



        var data = payments.Where(s => s.InvoiceNumber.Contains(searchInvoiceNumber)).ToList();


        Now data contains a zero, one or many PaymentDto items. It's up to you to decide what to do with that.



        Note that your Payment class isn't being used so far. If you're trying to populate that directly from the query, that's probably a separate question.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 21 at 4:18









        KhyronKhyron

        361210




        361210
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54277183%2fcannot-implicitly-convert-type-system-collections-generic-ienumerableproject-d%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Callistus III

            Ostreoida

            Plistias Cous