Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | Videos | Photos | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Login Close
User Id:
Password:
 
Forgot Password
Forgot Username
Why Register
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
World Class ASP.NET Hosting – Click Here for 3 Months Free/NO Setup Fee!
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » Tutorials » Building applications with DLinq Designer

Building applications with DLinq Designer

DLinq designer is the visual design surface to create the entity objects and bound the controls to the dlinq objects with relationships. We can easily create the windows form using the designer. The developer need not take more time to design the User Interface. The designer itself suggests you the controls suitable for the selected fields.

Total page views :  12898
Total downloads : 
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Become a Sponsor

In this article let us see the usage of DLinq Designer by an example how to create entity classes and the relationship with other classes. We will also see how to create a windows application which makes use of these classes. Using this DLinq designer we can reduce the development time and minimize the code for developing the application. We will also see the Linq queries to filter the records and to bind controls to the Data Source that is created using the objects built using the designer.

Open Visual Studio 2005 and select File-> New -> Project and select the option Linq Windows Application. Name the Project and select ok.

 

For creating the windows application, I have created the following database with two tables as Project & Requirement with the fields as listed below.


 
Now select the project, right click and select Add -> New Item and then select DLinqObjects from the List of Items available. The DLinqObject gets added to the project and the designer surface opens.

 

Expand the Server Explorer, open the database and expand the tables. Select the table "Project" from the list and then drag and drop it on the surface of the Dlinq designer. Build the project once after dropping the object on the design surface. Now if you open the DLinqObjects1.cs file, you can see the following code in it.

public partial class @__SQLEXPRESSDataContext : System.Data.DLinq.DataContext

             {

                      public System.Data.DLinq.Table<Project> Projects;       

                      public System.Data.DLinq.Table<Requirement> Requirements;       

                      [System.Diagnostics.DebuggerNonUserCodeAttribute()]

                      public @__SQLEXPRESSDataContext() :

                      base(new System.Data.SqlClient.SqlConnection(global::LINQWindowsApplication4.Properties.Settings.Default.DataConnection))

                      {

                      }

             }

[System.Data.DLinq.Table(Name="Project")]

public partial class Project : System.Data.DLinq.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged

{

            private int _ProjectID;

            private string _ProjectName;

  private string _ProjectDesc;

            private System.DateTime _StartDate;

            private System.DateTime _EndDate;

            private int _GroupID;

            private System.Nullable<bool> _ActiveFlag;

            private System.Data.DLinq.EntitySet<Requirement> _Requirements;

[System.Diagnostics.DebuggerNonUserCodeAttribute()]

public Project()

{

this._Requirements = new System.Data.DLinq.EntitySet<Requirement>(new System.Data.DLinq.Notification<Requirement>(this.Attach_Requirements), new System.Data.DLinq.Notification<Requirement>(this.Attach_Requirements));

}

       

[System.Diagnostics.DebuggerNonUserCodeAttribute()]

[System.Data.DLinq.Column(Name="ProjectID", Storage="_ProjectID", DBType="int NOT NULL IDENTITY", Id=true, AutoGen=true)]

public virtual int ProjectID

{

  get

            {

                      return this._ProjectID;

            }

            set

            {

                      if ((this._ProjectID != value))

                      {

                               this.OnPropertyChanging("ProjectID");

                               this._ProjectID = value;

                               this.OnPropertyChanged("ProjectID");

                      }

            }

}

The @__SQLEXPRESSDataContext is the connection object for the database connection. I used SQLExpress itself for the example. Then you can see the code for the entity table "Project" and the columns added to the designer. I have not given the code for other columns as it is similar to the field "ProjectID".

Select the menu Data -> Add New Data Sources in Visual Studio. This will open the wizard for adding data sources. The first step of the wizard will ask you to select the type of the source that will provide data to the application. Select Object from the options.  

The next step will list the available objects for binding the controls. As we have the Projects entity class on the designer, this will get listed under the project name. Select the Object "Project" and select next and then Finish the wizard.

Now you can see the data source added to the project under the Data Sources folder and also you can view the properties of the data source by selection the menu Data-> Show DataSources as shown below.

 

Now we are ready to Design the windows form. Open the form design surface. Now on the Data Sources explorer select the Project Datasource. You can see the following options when you select the drop down next to the Data Source "Project". This is to ease the design of the user Interface. You can choose how you want to present the UI to the user. For this example I have selected Details View.  

Now Drag and drop the Project Data Source on the form design surface. The Visual Studio places the corresponding data controls on the form according to the data type of the column/properties of the Table/Entity class. We don't need to select the controls and bind it manually. It's all done by the Visual Studio itself. You can also see a navigator on top of the form. This gives the flexibility of navigation on the records and also provides the editing controls in the navigation bar. This helps us to reduce the design time.

Add the following code to the form file to provide the necessary connections to the DataSource and then bind it. The con is the connection object created using the "@__SQLEXPRESSDataContext" connection which we have seen earlier.

namespace LINQWindowsApplication4

{

          public partial class Form1 : Form

          {

                       private @__SQLEXPRESSDataContext con = new @__SQLEXPRESSDataContext();

                       public Form1()

                       {

                                InitializeComponent();

                       }

                       private void Form1_Load(object sender, EventArgs e)

                       {

                                projectBindingSource.DataSource = con.Projects.ToBindingList();

                       }

          }

}

Now save the project, build it and execute it. You can see the below UI with the navigation feature also in it. The Save button is disabled as we have not enabled it and not added the code for it.  Before going for the editing feature we will add another data source and a detail control for that. Let's make this application as Master Detail application. 


 

Now close the application and go to the design and open the DLinqObject Design Surface. Now darg and drop the second table "Requirement" from the server explorer onto the Designer surface. Now you can see the following on the design surface. The Designer itself creates the Association relationship between the two entities.

Add data source for "Requirement" Object as we did previously for project entity. Use the Data Sources wizard for this. 


 
Now open the Data sources explorer and expand it. You can see Requirements as one of the property under Project Data Source which means that the requirement is one of the details of the project and requirement itself is an object with it's own properties.
 

 

Using drop down next to the "Requirements" property, set the view as "DataGridView" so that we can see the details in a grid when we navigate through the project records.

Drag and drop the Requirements object from the Data Sources explorer onto the form design surface. Select the Save button in the navigator and open the properties window. Using properties window. Enable the save button and select the click even for the save button. Add the following code for the click event of the Save button.

private void projectBindingNavigatorSaveItem_Click(object sender, EventArgs e)

{

          con.SubmitChanges();

}

Save the project and execute it.  Now try navigating through the records. Try editing and saving the changes.  

The next step what we can do is the search option on the Project name. This is very simple to achieve by using the Linq query. Lets see how we can do it.

Add a button next to the project name text box. Name it as you would want it. Here I named it as "Find". Add the following code to the Click event of the Find button. 

private void FindButton_Click(object sender, EventArgs e)

{

          var projs = from projects in con.Projects

                    where projects.ProjectName == projectNameTextBox.Text

          select projects;

          projectBindingSource.DataSource = projs.ToBindingList();

}

Save and execute the project. Now enter a valid project name in the project name text box and then click the Find button. This will bring you the details of the project name entered and also the corresponding Requirement details in the grid.  

Summary

DLinq designer is the easy way to create the entity objects and bound the controls to the dlinq objects. We can easily create the windows form using the designer. The developer need not take more time to design the User Interface. The designer itself suggests you the controls suitable for the selected fields. The developer has to just drag and drop the fields on the form surface which will reduce the development time. The designer also has the tools for creating the class objects which inherits from the other.


Login to add your contents and source code to this article
 About the author
 
Satheesh Kumar
I have 10 years of experience in software Industry. My experience includes Borland Technologies and Great Plains Dynamics (Now it is Microsoft Dynamics) and Microsoft Technologies such as VB.NET, C#, SQL Server and other microsoft tools and technologies.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010 Professional
Microsoft Visual Studio 2010 Professional will launch on April 12, but you can beat the rush and secure your copy today by pre-ordering at the affordable estimated retail price of $549 (US). Pre-order now.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Developer-Ready ASP.NET 2.0 Web Hosting with 3 MONTHS FREE
Now supporting .NET 3.0 Framework with Windows Workflow Foundation, Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), windows CardSpace (WCS)! Providing more flexibility for Developers with Web Services Support and a User/Permission Manger. Also supporting MS SQL 2005/2000 with Real-Time Backups, FREE Automated Attach .MDF Tool, FREE SQL Restore and Shrink SQL DB Tools, and SQL
 
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
 Post a Feedback, Comment, or Question about this article
Subject:  
Comment:  
Become a Sponsor
 Comments
Great Article by Mahesh On June 25, 2007
This is great article Satheesh. Gave me a head start on DLINQ.
Reply | Email | Delete | Modify | 

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2009.6.2
 © 2010  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.