当前位置: 动力学知识库 > 问答 > 编程问答 >

How to map joined tables to a list<Object> with LINQ?

问题描述:

When you setup linq, it maps all your tables to objects, I get that.

Now what happens when your linq query is inner joining with another table?

I read on here that it returns an anonymous object?

What if I have an object that maps to the columns in the inner join of 2 tables, how do I map?

Just looping through the collection as if it was a datareader and init my object and add it to a List?

网友答案:

Its not an anon type, below, I have the generated property for "PrinterTrays", in my case I have 1:M relationship between Printer and PrinterTray

[Association(Name="Printer_PrinterTray", Storage="_PrinterTrays", ThisKey="PrinterID", OtherKey="PrinterID")]
public EntitySet<PrinterTray> PrinterTrays
{
    get
    {
        return this._PrinterTrays;
    }
    set
    {
        this._PrinterTrays.Assign(value);
    }
}

I'm assuming you're talking about joins that have proper pk / fk / constraints on them.

Really tho, with the power of linq and delayed execution, you can do some really awesome stuff by piping your data into your own data types or anon types to be serialized for say json.

you need to watch these videos on linq to sql and these videos on linqpad

分享给朋友:
您可能感兴趣的文章:
随机阅读: