Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. LINQ DataSource and Foreign Keys

LINQ DataSource and Foreign Keys

Scheduled Pinned Locked Moved LINQ
csharptutorialdatabasewpfwcf
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    exhaulted
    wrote on last edited by
    #1

    Hi all, i've probably just missed something amazingly simple but.... I've been watching the tutorials based on Scott Gu's blog and the tutorial on binding a GridView to a LINQ datasource (video 4 i think) would really save me loads of development time while i'm creating prototypes for a project, if i could get it to work. An example table structure is as follows Customer ID (int) CustomerName (varchar) UserID (int) User ID (int) UserName (varchar) Now, as you can see, the userID field in customer maps to the user table quite nicely. I create a LINQ to Sql dbml file and drag the two tables into the page and i get a relationship created for me. Next up i create a LinqDataSource pointing at the Customer table with the * box ticked to select all columns. Then i bind a GridView control to the LinqDataSource and run the app, everything looks OK but i get the UserID int where i want the UserName. In the code behind file i can create a new Customer object (cust) and use the following to get at the username cust.User1.UserName but if i bind an itemtemplate field on the datagrid to this with Eval(User1.UserName) it doesn't work, i get the error message "User1.UserName was not found on the selected data source." I have tried User.UserName as well but to no avail, anyone have an answer for this? I'm running a web app in C# if it makes any difference :-D

    Kev http://esendexdeveloper.spaces.live.com/

    E 1 Reply Last reply
    0
    • E exhaulted

      Hi all, i've probably just missed something amazingly simple but.... I've been watching the tutorials based on Scott Gu's blog and the tutorial on binding a GridView to a LINQ datasource (video 4 i think) would really save me loads of development time while i'm creating prototypes for a project, if i could get it to work. An example table structure is as follows Customer ID (int) CustomerName (varchar) UserID (int) User ID (int) UserName (varchar) Now, as you can see, the userID field in customer maps to the user table quite nicely. I create a LINQ to Sql dbml file and drag the two tables into the page and i get a relationship created for me. Next up i create a LinqDataSource pointing at the Customer table with the * box ticked to select all columns. Then i bind a GridView control to the LinqDataSource and run the app, everything looks OK but i get the UserID int where i want the UserName. In the code behind file i can create a new Customer object (cust) and use the following to get at the username cust.User1.UserName but if i bind an itemtemplate field on the datagrid to this with Eval(User1.UserName) it doesn't work, i get the error message "User1.UserName was not found on the selected data source." I have tried User.UserName as well but to no avail, anyone have an answer for this? I'm running a web app in C# if it makes any difference :-D

      Kev http://esendexdeveloper.spaces.live.com/

      E Offline
      E Offline
      exhaulted
      wrote on last edited by
      #2

      Well i figured it out and the problem was with my Eval statement, nothing to do with LINQDataSources or the gridview. Eval("User1.UserName") is how it should be done instead of Eval(User1.UserName). I thought the days of missing ; or " off your code were long gone but obviously not :laugh:

      Kev http://esendexdeveloper.spaces.live.com/

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups