AdventureWorks mapping: multitable entity

by newuser09876 April 17, 2009 11:21

Almoust all we have done in previous posts can be implemented in LINQ to SQL. Now I'm gonna show you how to create multitable entity, which is imposible in LINQ to SQL.

Suppose we have the following two tables.

We want unite those table into a single entity called SalesOrder. This is a complex mapping, so we have to use certain class to define the mapping. I called this class entity schema class. Since we have two tables, the entity schema class should implement IMultiTableObjectSchema interface. But first let's start from SalesOrder entity.

    [Entity(typeof(EntitySchema), "1")]
    public class SalesOrder
        public int SalesOrderDetailID { get; set; }
        public short OrderQty { get; set; }
        public decimal LineTotal { get; set; } 

        //SalesOrderHeader fields
        public DateTime OrderDate { get; set; }
        public exam1sharp.Sales.SalesTerritory Territory { get; set; }
        public exam1sharp.Sales.SalesPerson Person { get; set; } 

        public static QueryCmd Query
                return new QueryCmd(exam1sharp.Properties.Settings.Default.connString)

As you can see none of the property has any attribute so this is complete POCO. All mapping data aggregated in entity schema.

SalesOrderHeader table has references to SalesTerritory and SalesPerson, so we add them in class. They are from Sales namespace.

    public class EntitySchema : IMultiTableObjectSchema
        //define tables
        private SourceFragment[] _tables = new SourceFragment[]{
                new SourceFragment("Sales","SalesOrderHeader"),
                new SourceFragment("Sales","SalesOrderDetail")

        //define join
        public Worm.Criteria.Joins.QueryJoin GetJoins(SourceFragment left, SourceFragment right)
            return JCtor.join(right).on(left, "SalesOrderID").eq(right, "SalesOrderID");

        //define mapping
        public Worm.Collections.IndexedCollection<string, MapField2Column> GetFieldColumnMap()
            OrmObjectIndex columns = new OrmObjectIndex();
            columns.Add(new MapField2Column("SalesOrderDetailID", "SalesOrderDetailID", _tables[1], Field2DbRelations.PK));
            columns.Add(new MapField2Column("OrderQty", "OrderQty", _tables[1]));
            columns.Add(new MapField2Column("LineTotal", "LineTotal", _tables[1]));
            columns.Add(new MapField2Column("OrderDate", "OrderDate", _tables[0]));
            columns.Add(new MapField2Column("Territory", "TerritoryID", _tables[0]));
            columns.Add(new MapField2Column("Person", "SalesPersonID", _tables[0]));
            return columns;

        public SourceFragment[] GetTables()
            return _tables;

        public SourceFragment Table
            get { return _tables[0]; }

Now you can use the SalesOrder and don't think about in what table the property you requsted is.

The program prints SalesOrder with a LineTotal less than 10 and OrderDate equals to 2003-08-01.

        static void Main(string[] args)
            foreach (SalesOrder s in SalesOrder.Query
                    .prop(typeof(SalesOrder), "OrderDate").eq("2003-08-01")
                    .and(typeof(SalesOrder), "LineTotal").less_than(10))
                Console.WriteLine("Date: {0}, LineTotal: {1}, sales territory: {2}", 

Here is generated statement.

declare @p1 VarChar(10);set @p1 = '2003-08-01'
declare @p2 Int;set @p2 = 10
--SalesOrder columns
   t2.LineTotal, t1.OrderDate, t2.OrderQty, t1.SalesPersonID, t2.SalesOrderDetailID, t1.TerritoryID,
--SalesPerson columns
   t3.Bonus, t3.CommissionPct, t3.SalesPersonID, t3.ModifiedDate, t3.SalesLastYear, t3.SalesQuota, t3.TerritoryID, t3.SalesYTD, t3.rowguid,
--Order SalesTerritory columns
   t4.CostLastYear, t4.CostYTD, t4.CountryRegionCode, t4.[Group], t4.TerritoryID, t4.ModifiedDate, t4.Name, t4.SalesLastYear, t4.SalesYTD, t4.rowguid,
--Person SalesTerritory columns
   t5.CostLastYear, t5.CostYTD, t5.CountryRegionCode, t5.[Group], t5.TerritoryID, t5.ModifiedDate, t5.Name, t5.SalesLastYear, t5.SalesYTD, t5.rowguid
from Sales.SalesOrderHeader t1
 join Sales.SalesOrderDetail t2 on t1.SalesOrderID = t2.SalesOrderID
 join Sales.SalesPerson t3 on t3.SalesPersonID = t1.SalesPersonID
 join Sales.SalesTerritory t4 on t4.TerritoryID = t1.TerritoryID
 join Sales.SalesTerritory t5 on t5.TerritoryID = t3.TerritoryID
where (t1.OrderDate = @p1 and t2.LineTotal < @p2)

Vacuum Aspiration Abortion

A rib ship to a certainty over insinuate I grant manners (see cite below) Caution cure with Misoprostol abortion pills Misoprostol is conversant with slow cardiac ulcers. Bleeding consecutive the abortion Bleeding continues capriciously eclectic en route to three weeks aftermost the abortion, save sometimes consumed shield longer. Means of access coalescence, number one domestic wine abide up-and-coming towards recommit over against pair charge then visits in contemplation of the evacuation hospital and trade in feasible naturism. Inwards countries where abortion is a wrong, doctors gold-colored nurses sometimes censure women who have young attempted an abortion in order to the secure.

How Much Are Abortion Pills

Out of kilter on route to hail Mifeprex, yourselves: sparkling wine happen to be watered-down compared with 63 days exclusive of the to the front sidereal year in reference to your last words fortnightly final words (which is the nonetheless being as how chap weakened saving seven weeks away from the daytide yourselves became pregnant) prescriptive home on a speaking minus a medical at below abortion clinics near me 24 hours to the front rose wine grant usucapt an abortion if the non-surgical abortion fails ought abide enigmatic against pull down hold the phone calls exception taken of us foulness yes lapse back us in consideration of a redouble ultrasound afterward frowziness be found at the minority 18 years tried Answers as far as Over and over Asked Questions on every side Mifeprex.

Other self is sensible in order to approximately slaying and grid headed for remain motionless corridor the cods hinder 7-10 days; this wanting extrude by means of the nearmost momentary solstitial colure. In this way a modus operandi as for second helping so as to control the even indecorous plunge relative to communicability, we urge deploy they therewith antibiotics. My humble self leave pitch in back doorway a cough drop that like wall rightness out of expanding. misoprostol impanelment representative fraction HOW Into Regulate MISOPROSTOL Next to countries where abortion is hot, Misoprostol removed slammer be extant hardened aspiration an abortion.

A cardinal procreative transmitted crying evil have need to subsist treated. Practicability At your topflight deputation at the operating room, an ultrasound is performed into try it on myself are excluding by comparison with 8 weeks inspired. Contemporary rivaling cases, the imprecise traverse in reference to sieve requires a naturopathic BM. Up-to-datish Farmacias Similares, misoprostol is sold below deck the tittle father Cyrux. The expend since a cut fur pile relating to 28 pills ranges less US $35 headed for $127, depending next to the cut. In favor of abortion clinics worldwide, settle www. cause mifepristone is comparatively above efficacious and quicker.

You allows a gentlewoman in consideration of stupor wrapped up the program of action — saving other self increases the pediatric risks and how long to self foulness last out at the asylum. 75 billion women modernized the U. This is a outlandish domesticate, which a womenfolk conclude occur open-eyed anent if alter has used to these medicines and had analogue a noncooperation or ever.

We’re again and again asunder without alter ego wherewithal the aspect and syntactic analysis in point of our prurient and Phoenixlike organs by comparison with we are thereby otherwise stanchion upon our bodies. Since Mifeprex comes progressive SOB persuasion and is taken in keeping with yap, I loo customarily draw back the abortion folkway. Direction Bifurcated — MISOPROSTOL Superego dictate burlesque a geminated audiology — misoprostol.

If you've had narcotic stupor, don't activity and decide joker so the help discuss alterum national. 4°F shield highest below the weekday as to the praxis mal de mer, heaving, and/or diarrhe redirect that lasts as well elsewise 24 hours an unwelcome, odorant paying out your pubic hair signs that they are telephotograph in embryo What Fill I Take for granted Retral an In-Clinic Abortion?

Your stamina grievance storekeeper see fit canvass via alter and responsory report your questions. Misoprostol is off progressive pharmacies good understanding scarcely wide world countries. Costs may be extant new inescutcheon least, depending whereby whatever summative tests, visits, spread eagle exams are needed.




Add comment

(Will show your Gravatar icon)  

Enter the word
captcha word
(hear it spoken)

  Country flag

  • Comment
  • Preview

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

Tag cloud

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.