开发者

DevExpress XPO wrapping existing table relationships

开发者 https://www.devze.com 2023-03-09 18:30 出处:网络
I\'m experimenting with XPO and attempting to wrapper some existing tables. Does anyone have experience with doing this? The problem I\'m running into is determining how XPO determines the names of th

I'm experimenting with XPO and attempting to wrapper some existing tables. Does anyone have experience with doing this? The problem I'm running into is determining how XPO determines the names of the linking fields for relationships.

For example, I have two tables,

Merchant( MerchantID, ProcessorID开发者_C百科, etc...) linking 1 to 1 with Processor

Processor( ProcessorID, etc...) linking 1 to Many with Merchant

DevExpress says to set up the relationship as follows:

public class Merchant : XPLiteObject
{
    [Association("Processor-Merchants")]
    public Processor Processor;
}

public class Processor : XPLiteObject
{
    [Association("Processor-Merchants", typeof(Merchant))]
    public XPCollection Merchants {
        get { return GetCollection("Merchants"); }
    }
}

But my question is, how is XPO going to know which are the key fields linking these relationships together? This example compiles and runs in an XAP application, but the data is missing for each relationship (probably due to the fact it doesn't know which fields are linking the tables together).

Is there syntax I'm missing that I need to add to establish these relations? Or, maybe some extra code needed? The DevExpress documents say the above should work, but it doesn't.

Any help?


After experimenting with different syntax, I found that if I added the following to the Merchant class it works:

public class Merchant : XPLiteObject
{
    [Persistent("ProcessorID")]
    [Association("Processor-Merchants")]
    public Processor Processor;
}


The PersistentAttribute can be used both for mapping classes to tables and for mapping properties to columns.

If you leave it out, the table-/columname will be the same as the class-/propertyname, and table/column will be created if missing. That's what happened at your first attempt.

http://documentation.devexpress.com/#XPO/clsDevExpressXpoPersistentAttributetopic

0

精彩评论

暂无评论...
验证码 换一张
取 消