Sunday, May 24, 2009

Adding the Linq to SQL ORM to your .NET project

I am working on a new personal project (I mentioned it in my videocast), I am building it in MVC, since it is a small project I wanted an easy to use and implement ORM. I chose LINQ to SQL after hearing several good things. It has been a real breeze to set up and use. So, without further ado, I have put together a tutorial on how to set up LINQ-TO-SQL.






First add a new Linq to SQL class to your project. Since I'm using MVC, I'm putting my Linq to SQL classes in my Model folder. However, you can put them wherever you want. When I add the classes I get the Object Relational designer telling me to drag over items from my server explorer to map them.





Now you need to add your SQL server to your project's Server Explorer. Right click on data connections and go to add a new connection.  Put in the ODBC info for your server, and make sure to test your connection before closing. Now, if you expand your tables all you have to do is drag them over to the OR Designer.



You can very easily add relationships to your objects. I'm not sure if that would automatically happen if they are related in the DB. Someone will need to try and let me know. In order to add a relationship you right click on one of your tables, click "Add" and choose "Relationship." You can then specify the parent and child tables as well as what columns hold the relationship.




Next I'm going to build an interface to list my methods that I'm going to build to deal with my objects quickly. As you can see, mine are specific to my application, but I think they will be helpful to you anyway.






To create these methods, first I'm going to create an instance of the Data Context that was created with my .dbml. Then I'm going to use LINQ to query my objects for me and return them. I'm just making a basic Save method, and some small queries that I think I will need.




There you have it. That's how easy it is. I KNOW! You can download my source here. Now we have my model set up we can move to the rest of our MVC for web forms developers series. Stay tuned!!



Friday, May 22, 2009

True Success









"To laugh often and love much;


 to win the respect of intelligent persons


and the affection of children;


to earn the approbation of honest citizens


and endure the betrayal of false friends;


to appreciate beauty;


to find the best in others;


to give of one's self;


to leave the world a bit better,


whether by a healthy child,


a garden patch or a redeemed social condition;


to have played and laughed with enthusiasm


and sung with exultation;


to know even one life has breathed easier because you have lived 


this is to have succeeded."


-Ralph Waldo Emerson



I don't consider work, and a career to be a separate entity from life. Many do, and I thnk it's because they don't love what they do or enjoy where they are and the people they are amongst. I contend that the only way to achieve the success described above is to surround yourself with people that love what they are doing as much as you do. Also on the way making time for family, friends, and the beauty that is children. I may be the eternal idealist, but please, never settle for any less.





Sunday, May 17, 2009

Just A Video Update


Info about Code Stock, BarCampNYC, WPF, MVC, BCBG, and Snoop D-O-Double-G.


Sites:


 http://codestock.org


http://barcamp.org/BarCampNYC4


Please excuse the big trashy can of Raid that makes itself obvious in the end. I have been being ATTACKED by SPIDERS, they TARGET me.



Friday, May 8, 2009

Central Jersey User Group, Richmond CC, and NWC



     So, I heard about this thing called Co-working (in a tweet by @NathanBowers) and I went online to check it out. Turns out there are groups of freelancers that rent an office and all get together and work at the same place. This is a GREAT idea because my and Steven (my cat for those not dedicated) are getting really sick of each other.I found this place called New Work City online. The other day I was in the city, so I peeked in to check it out. The people seemed like they were motivated entrepreneurs, and not at all like muderers. So, today I have stopped in to get some work done. I have the saddest little mini setup, but I love it. You will see an article about it on Datamation next week. The group is playing guitar hero later and going to see Star Trek.... what the heck do I have to lose? (I have been taking this attitude lately a lot, it makes life an adventure).


    Richmond Code Camp was AWESOME. I got to meet a lot of twitter faces, the people in the south are so nice (it takes some adjusting before I realize they aren't trying to kidnap me). My talk went OK. It was short, because I took out some coding and had some stuff pre-done. Also, I need to learn to TEACH instead of PLOWING through the material like it is a race to the finish. I guess practice makes perfect. I'm looking forward to next time, I hope the people that came learned SOMETHING.


 So, Thursday nights at Infragistics in East Windsor they've been having a pseudo-open-spaces type user group. I have been stopping by (twice so far) and I've been learning a lot. Yesterday I learned about IoC, Functional Programming, and MVVMCVCCC (or whatever model WPF is). I would highly reccomend stopping by. It starts at 6:15.



Monday, May 4, 2009

A Story of a Girl and Her Netbook


   There was once a girl who lived in a big forest (or possibly a house where some trees are). She was beautiful, wise, and broke.



Sunday, May 3, 2009

Developers Block


So, I'm stuck. Usually I try for two posts a week, but I can't accomplish anything tonight. I can't write, and I can't get any work done. I'm sure this has happened to you. What do you do?



I'm going to walk away from my machine and watch some James Bond (best movie I could find onDemand). I would love to hear about what you do when you find yourself here.