none
How to cast Stored Procedure using LINQ to SQL? RRS feed

  • Question

  • Guys,
    I have a problem:
    ------------
    Problem: How to cast Stored Procedure using LINQ to SQL?
    ------------

    On my Previous Code w/o SP:

    Code Snippet 1:
    using (DataClasses1DataContext db = new DataClasses1DataContext())
    {
    var q = db.ExampleTable;
    foreach (var item in q)
    {
    ListViewItem lvi = new ListViewItem(
    new string[]
    {
    item.AirName
    });
    lvi.Tag = item; -- ( I Tag it so that it could easily get the PK which i will Cast in my next snippet)
    this.listView1.Items.Add(lvi);
    }
    }

    Code Snippet 2:
    using (DataClasses1DataContext db = new DataClasses1DataContext())
    {
    var q = (ExampleTable)this.listView1.SelectedItems[0].Tag; -- Cast the Table which i refer above example.
    }

    ---------------------------------------------------------------------------------------------------

    However w/ SP:

    Code Snippet 3:
    using (DataClasses1DataContext db = new DataClasses1DataContext())
    {
    foreach (var item in db.ExampleTable()) -- SP
    {
    ListViewItem lvi = new ListViewItem(
    new string[]
    {
    item.AirName
    });
    lvi.Tag = item; -- ( I Tag it so that it could easily get the PK which i will Cast in my next snippet)
    this.listView1.Items.Add(lvi);
    }
    }

    Code Snippet 4:
    using (DataClasses1DataContext db = new DataClasses1DataContext())
    {
    var q = (db.ExampleTable())this.listView1.SelectedItems[0].Tag; -- Can't Cast, it show prompt...
    }

    Or what should be the remedy?
    tnx for replying!
    Thursday, December 1, 2011 2:14 PM

Answers

All replies

  • Hi Jed A.Monsanto,

    Forgive my dull. Could you please explain what you want to do? Code Snippet2 can cast the tag but Code Snippet4 can't cast? The tag you select out is a ExampleTable typed object, you can cast it as Code Snippet2, but the DataClasses1DataContext seems make no sence, you didn't use it anywhere in the Code Snippet2. I appreciate if you can provide more information about your problem, this is, so I can help you more effectively.

    Best Regards.


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us



    Monday, December 5, 2011 3:13 AM
    Moderator
  • Hi Jed A.Monsanto,

    Have you fixed your issue? I look forward to hearing from you. If you have any problems, please feel free to let me know.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Wednesday, December 7, 2011 2:02 AM
    Moderator
  • Hi Allen_Li1988,

    sorry, im not log-in for awhile... yes, i solve my problem, it's just a Return Data Type that needs to Cast...

    Tuesday, December 13, 2011 11:57 AM
  • Hi Jed,

    I'm glad to hear that you have solved the issue. If you have any problems, please feel free to post in the forum.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, December 13, 2011 4:07 PM
    Moderator