Difference between revisions of "DD Class8"

esse quam videri
Jump to: navigation, search
(LINQ)
m (Text replacement - "</csharp>" to "</syntaxhighlight>")
Line 74: Line 74:
 
         public string CheeseDescription { get; set; }
 
         public string CheeseDescription { get; set; }
 
     }
 
     }
</csharp>     
+
</syntaxhighlight>     
 
      
 
      
 
Now we can access the cheese class by creating a data connect on the fly with a Table of cheeses
 
Now we can access the cheese class by creating a data connect on the fly with a Table of cheeses
Line 82: Line 82:
 
     db = new DataContext(connetionString);
 
     db = new DataContext(connetionString);
 
     cheeseTable = db.GetTable();
 
     cheeseTable = db.GetTable();
</csharp>     
+
</syntaxhighlight>     
 
Now I can query the cheeseTable just like a data context in LINQ to SQL
 
Now I can query the cheeseTable just like a data context in LINQ to SQL
  

Revision as of 18:28, 25 January 2016


Cheese Editor

GridView/DetailsView

http://iam.colum.edu/dd/classsource/ado/GridViewDetailsView.aspx

Editing Multiple tables requires more work

http://brookfield.rice.iit.edu/jmeyers/ITM564/classsource/binding/CheeseDataBindingFull.aspx

Nesting Contols

http://brookfield.rice.iit.edu/jmeyers/ITM564/classsource/binding/CheeseDataBindingFull1.aspx

LINQ

c# 3.0 got some new features and key words

var

is a implicitly typed local variable. it is strong typed you don't need to declare the type when you declare the variable.

Anonymous Types'

allows creation of structural types without declaring an name first http://msdn.microsoft.com/en-us/library/bb397696.aspx

Lambda Expressions =>

similar to anonymous methods. don't need to be declared first and don't need to specify return type http://msdn.microsoft.com/en-us/library/bb397687.aspx

new keywords http://msdn.microsoft.com/en-us/library/bb310804.aspx

http://iam.colum.edu/dd/classsource/LINQBlog/LINQTest.aspx

http://msdn.microsoft.com/en-us/library/bb397933.aspx

LINQ to SQL and DBML

Linq to SQL is an Object Relatinal

Designer O/R Designer

http://msdn.microsoft.com/en-us/library/Bb384429%28v=vs.90%29.aspx

It allows you to quickly make


http://iam.colum.edu/DD/classsource/Data/LINQ/LINQBinding.aspx

http://iam.colum.edu/DD/classsource/Data/LINQ/CheeseLINQ2.aspx

LINQ Data Mapping

We can decorate our cheese class with some fields using classes from

using System.Data.Linq.Mapping;

using System.Data.Linq;

using System.Configuration; <csharp>

   /// 
   /// Cheese Class for Our Repo until we get to linq ignore the [] lines
   /// 
   [Table(Name = "Cheese")]
   public class Cheese
   {
       [Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
       public int CheeseID { get; set; }
       [Column]
       public string CheeseName { get; set; }
       [Column]
       public string CheeseDescription { get; set; }
   }

</syntaxhighlight>

Now we can access the cheese class by creating a data connect on the fly with a Table of cheeses <csharp>

   private Table cheeseTable;
   private DataContext db;
   db = new DataContext(connetionString);
   cheeseTable = db.GetTable();

</syntaxhighlight> Now I can query the cheeseTable just like a data context in LINQ to SQL

Home Work

Create a new .dbml file (new LINQ to SQL Class) and add it to you website. You can add bth tables to the same dbml file. Remeber to set the DataContect and Entity namespace.

Create 2 aspx pages, one for each or your tables in the dbml.Use the DataContext to get data from your db. Bind the data to a control on the page. Add buttons or contols to the page to use INSERT, UPDATE, SELECT and DELETE data on the page using LINQ.