AdventureWorks mapping: almost full Sales.Store implementation

by Alexey Shirshov April 08, 2009 10:21

It's time to complicate an example.

First of all I'm going to assign database table to our entity. In the previous examples, we have to specify table in From method. To avoid this we should mark entity class with EntityAttribute attribute.

[Entity("Sales", "Store", "1")]

Here we specify Sales database schema and Store table name. 1 - entity schema version (forget itSmile).

The next improvment - implement static Query property returns QueryCmd instance.

    [Entity("Sales", "Store", "1")]
    public class Store3
    {
        [EntityProperty("CustomerID", Field2DbRelations.PK)]
        public int ID { get; set; }

        public string Name { get; set; }
        
        public DateTime ModifiedDate { get; set; }
        
        public XmlDocument Demographics { get; set; }        
        
        [EntityProperty("rowguid", Field2DbRelations.RowVersion)]
        public Guid Timestamp { get; protected set; }

        public int SalesPersonID { get; set; }

        public static QueryCmd Query
        {
            get
            {
                return new QueryCmd(exam1sharp.Properties.Settings.Default.connString)
                    .From(typeof(Store3))
                    .Select(typeof(Store3));
            }
        }
    }

The program prints stores whos name starts with A.

        static void Main5(string[] args)
        {
            foreach (Store3 s in Store3.Query
                .Where(Ctor.prop(typeof(Store3), "Name").like("A%"))
                .ToList())
            {
                Console.WriteLine("Store id: {0}, name: {1}, timestamp: {2}", s.ID, s.Name, s.Timestamp);
            }
        }

Tags:

Quickstart

Add comment


(Will show your Gravatar icon)  

Enter the word
captcha word
(hear it spoken)


  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen | Modified by Mooglegiant

The Author

My name is Alexey Shirshov. I'm a professional developer with wide specialization. I prefer VB.NET to C#, I hate ASP.NET but there is no better than it. You can contact me by this page.