Google Search

Google
 

Monday, July 21, 2008

Video: Mapping Schemas to Classes in LINQ to SQL

Presenter:Mike Taulty

In order to use LINQ to SQL we need to let the framework know how to map between the relational schema and our .NET types. In this video we look at the mechanisms for doing this.

The following text is a software generated transcript of the video. Click on a minute link to jump to a location within the video


Minute 0

No virus might told the and I worked in a developer and platform group in Microsoft in the UK and this is one of a series of short videos about the new technology coming with visual studio coating orchids as an ex version officials do that is called a sequel and I say this is one of a series if you ve not seen the end of his introductory session it likely that the outlook such before you wonder that one stock retrocession ears the idea that we have and object relational mapping framework going on in mid sequel and we have relationships and tables and databases and return those into objects at properties in memory at order to that feeling it is some kind of mapping singers classism use as low as it is linked to sequel out I have a bit of a look at how we do that in this particular session avocet and I m working with visual studio company augurs is that marked preview of the

Minute 1

Studio that is available on the Internet and it is right to make a consort facing a just and play around then I decided I could have a little bit education hoping to hear a similar talk of using previous sessions will am going to the cogeneration to this point before based in a classical Northwind edit context it s a data context result that in the previous session related to the Northern database I felt at their table of customer called customers and will just go ahead and pasting the classical customer hear anything certain it is deliberately very simple string country stinks in company name and strength across variety now that implies looking writers answer queries so throughout and is very naked context and I say that the theory is

Minute 2

See a complex customers select city is squaring right than I will go ahead in this reach around that collection our writer and see the costs arising something like that so if we don t run this code will find an unreasonably the framework says Jorge nanosecond looked only very tightly customer wrote you haven t told me in what way that relates to the date on and getting from the database essentially I don t know how to map the customer here this listing here to the database you haven t told me any way of doing so let s just make this a little bit more interesting and rather disarming three fields here that have free properties with slightly different names on sewer go ahead and have a property of type string will call the town as is afield will call it

Minute 3

ID as a profitable idea of fun is well thrown in against strange recall that company is Fergus Fielden company Motorola Morin books let s call this son home something like that before the nation address and a good one to changing the names of these things and make the further away from the action is on the table now one of the ways in which we can specify nothing is values of an XML file so the data content has another constructor on it let s make that available on data context to do this context is not only connection straight a single exhorts and one kind of mapping source is a think of an XML mapping source as glass also was a

Minute 4

XML mapping source blocked from URL math X and now I know God is not that it notifies us and take a look at the okay so we had a very simple XML file database called Norseman in which we say we want to use a table call customers which program acts to tackle customer I thought it is three columns are tried to be more explicit about the first one so the first line databases go customer ID in our class and representing it with the ID property but optionally you can also specify the storage attribute if you do that it needs of the framework will go straight to your field rather than going to the property so you might want to have things like validation logic and he that you don t want framework to use in which case you can directly straight to the property or not is up to you it is not the primary key and a canal does the database generate this column which isn t what they come to insert conciliatory queries

Minute 5

Rallies if his identity in the database when we are doing an optimistic concurrency which will progress in the subsequent session do we need to check this column on does this column represent the row version of the table is that a computer column is this a column involved in determining the type of an object from the point of view of inheritance gamble took the inheritance of follow on session at any other columns at the less specific about the last a few bits and pieces in them and not so much if it only visit our code I think we ve got the seal for the wrong thing council chamber at the ID was it after holding centre to company as progress five on and we can see that we are now reading the date on getting the right data based on the mapping that were providing in this XML file that has had to go from database stuffed object stuff and notice that we could potentially generate this dynamically in London

Minute 6

Wanted to sell a look further at this virtue visit our code hand lets drop in some code from orders tables well into here so try and place the time his father other than that I can thought he Febiger so it are the oldest class I and all the readers have the order ID and the customer ID Alresford customer and add to the property called orders that manages the orders flat customer so glad of another bit paste here what this is doing is a property called orders in it is other titled entity sets of order will top medicine such concessions were essentially this current model and a want in any relationship where we saying that the customer has a bunch of orders and is a diseased set class doesn t things for as like making sure that obviously out to get tracked by the data context and like doing deferred loading on this colour

Minute 7

If you wanted to twitter a smarter than just a list or something like that glad that it is well most glad this is well formatting to a pop over to the map file and will add in here a new table so we need to match the orders table us if we can find the live ex lover that the case was only got the orders table mats and classical order and were pulling out all the riding customer ID and only to model relationships in custom and order with you and he widow at the sex analysis we have an association with the initiation says the name is kind of redundant in our orders collect which is backed by orders field we have a relationship when we look at the ID of this table to the customer ID at the other table and the other table is orders but says that the tobacco code red

Minute 8

Really if we can go ahead and write out not only be three seals with at the moment but also that s right out customer the orders stop councils and other civic and better file on a very writing at the number of orders that we thought that particular customers so we modelled as well and that mapping file an association between the customers able to the orders tabled naturally to build another one with the Association of the customer property in order was dated back to its customer record of is well now I think this earlier on in the video this mapping file is just one way of guidance in the relational scheme and archives programme against net with the article had actually tightened on to combat a code we can get rid of this mapping source altogether and I stayed away from the constructor that we ve got here and everything after his archives so we can come to the customers massively consider this corresponds to a table in the database and aimless customers

Minute 9

Database this track response to a colour laser lesson aim is customer ID and it is the primary key with the brussels of column the name in the databases company name at this guy is not a column and the name in the database is country and am I get us through that don t let if you have to be that orders to say it is an association in this table we have the ID in the other table we have customer ID at the storage you were using the orders field and outfit enough through the order table is well suggested that such the table then because orders and this is a column domain FAQ matches what s the name matches the field they shall these allow in this is frantically through

Minute 10

Our outlook on here and again than a Majesty a database we should be okay to say and whether in distress the final analysis I work for is that it is very well what looks like the bad column analysis review what we don t pressure because of the idealist ran at and every guy data going back again and now a mapping with attributes in coders opposed to nothing with them elements and attributes in XML now having looked at this a bit man has easily been doing this manliness session as Palestinian territories shall use the cogeneration diagramming till to do this for us in files that have a look at what our options are around cogeneration which of these two things we can get done for us by a tool will also look bit more at things like how we deal with collections of children here and

Minute 11

Also look at how we can use mapping in order to bring in things like store procedures and database functions and other things like that but all three of these the necessity of an idea that we can attribute of code or we can produce XML either statically or dynamically and that so the frame of nose to go from our records are coming from the database into instances of classes that we create no just a quick summary event we had a quick look at mapping how it goes between the relational world of tables primary keys forages and so on and across to object in memory instances of types of memory and was into ways we can do it here we can specify XML file what we want all we can specify a bizarre coincidence of what we want and we also know from watching introductory video that it more unlikely that the way you get one of the solutions is by using cogeneration rather than try to title the stuffing in a session with activities to show at work struggle

Minute 12

An impression in actually necessarily titled a similar subtlety were specifically getting the benefit Francie would normally go ahead with now where you go to warrant making online there are enter on yen the URL that their on screen it will provide you information on the project including an equal a great laugh out linkingaction net and encourage it go have a look about you like moving and blog and finally if you aren t providing feedback on the specific enjoying a fashion your free to mail me on my e mail address is just their on screen free to mail me tryout zone and other than that I felt they could have lived in and out to catch again in the future

Click here to go to original video page

0 comments: