I'm reading Pro ASP.Net MVC2 and I've gotten to a point where nothing is explained well enough. For example, the following tells me to create this C# code manually:
Implementing the Auctions Domain Model With LINQ to SQL, you can set up mappings between C# classes and an implied database schema either by decorating the classes with special attributes or by writing an XML configuration file. The XML option has the advantage that persistence artifacts are totally removed from your domain classes,4 but the disadvantage that it’s not so obvious at first glance. For simplicity, I’ll compromise here and use attributes. Here are the Auctions domain model classes now fully marked up for LINQ to SQL:5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq.Mapping;
using System.Data.Linq;
[Table(Name="Members")]
public class Member
{
[Column(IsPrimaryKey=true, IsDbGenerated=true, AutoSync=AutoSync.OnInsert)]
internal int MemberID { get; set; }
[Column]
public string LoginName { get; set; }
[Column]
public int ReputationPoints { get; set; }
}
[Table(Name = "Items")]
public class Item
{
[Column(IsPrimaryKey=true, IsDbGenerated=true, AutoSync=AutoSync.OnInsert)]
public int ItemID { get; internal set; }
[Column]
public string Title { get; set; }
[Column]
public string Description { get; set; }
[Column]
public DateTime AuctionEndDate { get; set; }
[Association(OtherKey = "ItemID")]
private EntitySet<Bid> _bids = new EntitySet<Bid>();
public IList<Bid> Bids { get { return _bids.ToList().AsReadOnly(); } }
}
Where exactly do I have to write this in? Or is he just displaying generated code by the Linq-to-sql DBML?