LINQ in Orcas Beta 1

I’m using a virtual machine with Orcas installed Beta 1, the version to come of Visual Studio 9. In another one “post” I’ll enumerate the main new features, but now, I want to concentrate in showing a small great step to me, that brings built-in code generation for LINQ. (code of this example in

Those that saw LINQ, the Microsoft technology, in some way, an object relational mapping, remembered that there was a command line tool named SQLMetal, that generated code to make that mapping. Now, the SQLMetal is still alive, but, following with the idea of to do everything from the Visual Studio, the Orcas version provides a new type with item: Linq to SQL.

In the example, I dragged tables from a connection of data SQL Server, and soon they appeared in the new designer (in this case, using a datasbase from a Hands On Lab Orcas Beta 1, on a database similar to the one of DinnerNow, with restaurants, menus, and items of menus):

In a file of code produced automatically by “designer” (Redmond boys saw the light, the generation of code… for years that people have been adding more code generation utilities in Visual Studio versions, e.g., software factories… ), in this example, a DinnerNowDataContext:

public partial class DinnerNowDataContext : global::System.Data.Linq.DataContext { [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] public DinnerNowDataContext(string connection) : base(connection) { } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] public DinnerNowDataContext(global::System.Data.IDbConnection connection) : base(connection) { } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] public DinnerNowDataContext() : base(global::DbmlLibrary1.Properties.Settings.Default.DinnerNowOrcasLabsConnectionString) { } public global::System.Data.Linq.Table<Menu> Menus { get { return this.GetTable<Menu>(); } }

in a similar way as the code generated by SQLMetal tool. As before, it defines “business entities” that are the classes that correspond to the database tables:

[global::System.Data.Linq.Table(Name="dbo.Menu")] public partial class Menu : global::System.Data.Linq.INotifyPropertyChanging, global::System.ComponentModel.INotifyPropertyChanged { private global::System.Guid _MenuId; private global::System.Nullable<global::System.Guid> _MenuTypeId; private global::System.Guid _RestaurantId; private global::System.DateTime _StartDate; private global::System.DateTime _EndDate; private global::System.Data.Linq.EntitySet<MenuItem> _MenuItems; private global::System.Data.Linq.EntityRef<MenuType> _MenuType; private global::System.Data.Linq.EntityRef<Restaurant> _Restaurant; [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] public Menu() { this._MenuItems = new global::System.Data.Linq.EntitySet<MenuItem>(new global::System.Action<MenuItem>(this.Attach_MenuItems), new global::System.Action<MenuItem>(this.Detach_MenuItems)); this._MenuType = default(global::System.Data.Linq.EntityRef<MenuType>); this._Restaurant = default(global::System.Data.Linq.EntityRef<Restaurant>); } [global::System.Data.Linq.Column(Storage="_MenuId", Name="MenuId", DBType="UniqueIdentifier NOT NULL", IsPrimaryKey=true, CanBeNull=false)] public global::System.Guid MenuId { get { return this._MenuId; } set { if ((this._MenuId != value)) { this.OnPropertyChanging("MenuId"); this._MenuId = value; this.OnPropertyChanged("MenuId"); } } }

Thanks to the people of Southworks by the virtual machine with Orcas Beta 1.

Angel “Java” Lopez

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s