• 0

[C# Winforms] Need some databinding help


Question

So i'm currently making a basic WinForms application. I need to do grab some data from a Database and have done so as I would in ASP.Net, using LINQ-SQL. Now every tutorial i've read on the internet thus far is focused on DataSets, DataRows and all the horrible .Net 2.0 stuff.

I also need a basic Parent -> Child Combo-box arrangement, but can't seem to get anything working.

I want to conform to the standard .Net Winforms way of doing things, but it seems like LINQ and LINQ to Entities weren't designed for use with WinForms or am I just looking in the wrong place?

Anyone got some good links on databinding to LINQ-SQL or LINQ-Entity Datasources. I would preferably like some sort of built-in CRUD functionality as well, if at all possible.

Cheers,

MiG

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Ignoring the semantics behind Linq-To-Sql, what you can end up with is an IQueryable<...>, which inherits from IEnumerable<...> and IEnumerable. You can bind to that fine, or you can use the Linq extension method ToList() to get a List<T> back:

from u in Users where u.Name = "Matthew" select u;

returns an IQueryable<User> with all users who have a name 'Matthew'. You should be able to bind that directly.

Edited by Antaris
Link to comment
Share on other sites

  • 0
Ignoring the semantics behind Linq-To-Sql, what you can end up with is an IQueryable<...>, which inherits from IEnumerable<...> and IEnumerable. You can find to that fine, or you can use the Linq extension method ToList() to get a List<T> back:

from u in Users where u.Name = "Matthew" select u;

returns an IQueryable<User> with all users who have a name 'Matthew'. You should be able to bind that directly.

Yeah I got simple databinding working by binding from LINQ-SQL. The examples I saw though for master-detail relationships all defined the relationships and data to get automatic updates and that sort of thing, using things that werent available in LINQ to SQL.

How would I go about implementing validation on the fields as well? Is there a simple way?

Cheers,

MiG

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.