DD Class8

esse quam videri
Jump to: navigation, search


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;

    
    /// 

    /// 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; }
    }

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

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

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.