Geeks With Blogs
Saqib Ullah BootStrapper Know How
In my pervious blog we saw the sqlmetal.exe utility that is use to generate data model class for my LINQ data class. There is another way to generate data model by using a very cool Designing tool called DLinq Designer. By the help DLinq Designer we can easily generate data model class for LINQ, DLINQ by simply drag and drop tables from Server Explorer.
 
Testing Windows Application
·          Choose File->New Project within Visual Studio and navigate to the "LINQ Preview" node in the project-type tree-explorer.  Then select the "LINQ Windows Application" project icon and create a new LINQ enabled Windows Application.
·          Right Click on the solution and select Add->New Item from the context menu. Select DLinqObjects and give name LINQTest.cs
·          Drag and drop sample LINQ database tables from Server Explorer to DLinq Designer.
 
 
Fig. 1 Linq Designer
 
·          Save the designer file Visual Studio automatically generate partial classes of respective tables and create their associations automatically.
·          Open the Linq.cs from Solution Explorer that is generated by DLinq Designer and see the patient partial class. LINQ, DLINQ maintain the relationship between two entities by the new generic type called EntitySet<T> .and EntityRef<T>
 
Create RelationShip:
The steps to implement relationships between entity classes are as follows:
1. Add an EntitySet<T> private field in the parent entity class to collect the objects belonging to the child entity class.
2. Add the property that encapsulates the access to this private field. Additionally, we have to add the Association decoration to specify some properties, such as the relation name and the keys involved in the relation.
3. Add the initialization of this private field using its two parameter constructor.
4. Add an EntityRef<T> private field in the child entity class to retrieve the instance of the parent entity object.
5. Add the property that encapsulates the access to this private field. Again, we have to add the Association attribute to the property.
 
Code:
Following codes produced by the DLinq designer tool. 
[System.Data.DLinq.Table(Name="Patient")]
public partial class Patient : System.Data.DLinq.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged
{
private string _Name;
.... 
private System.Data.DLinq.EntitySet<Patient_Session> _Patient_Sessions;
   
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public Patient() {
this._Patient_Sessions = new System.Data.DLinq.EntitySet<Patient_Session>(
new System.Data.DLinq.Notification<Patient_Session>(this.Attach_Patient_Sessions), new System.Data.DLinq.Notification<Patient_Session>(this.Attach_Patient_Sessions))
;}
 
{
.... Details Omitted for Brevity
}      
 
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.Data.DLinq.Column(Name="Name", Storage="_Name", DBType="nvarchar")]
    public virtual string Name {
            get {
                return this._Name;
            }
            set {
                if ((this._Name != value)) {
                    this.OnPropertyChanging("Name");
                    this._Name = value;
                    this.OnPropertyChanged("Name");
                }
            }
        }
 
{
.... Details Omitted for Brevity
}      
 
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
private void Attach_Patient_Sessions(Patient_Session entity) {
   this.OnPropertyChanging(null);
       entity.Patient = this;
   this.OnPropertyChanged(null);
   }
       
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
private void Detach_Patient_Sessions(Patient_Session entity) {
   this.OnPropertyChanging(null);
       entity.Patient = null;
   this.OnPropertyChanged(null);
        }
    }
 
 
Generation Bug:
In the above code you have noticed that EntitySet<Patient_Session> constructor take this.Attach_Patient_Sessions  in both parameters which is wrong, so second parameter should be this.Detach_Patient_Sessions. One thing that I want to mention here is EntitySet<T> constructor accept System.Data.DLinq.Notification object.
 
Solution:
You have to change it manually to pass the Detachdelegate name as the second agrument. 
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public Patient() {
this._Patient_Sessions = new System.Data.DLinq.EntitySet<Patient_Session>(
new System.Data.DLinq.Notification<Patient_Session>(this.Attach_Patient_Sessions), new System.Data.DLinq.Notification<Patient_Session>(this.Detach_Patient_Sessions))
;}
 
Posted on Friday, May 25, 2007 12:19 AM .Net , Web Tech | Back to top


Comments on this post: DLinq Designer Bug

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Saqib Ullah | Powered by: GeeksWithBlogs.net