XPO 实现对视图的显示

首先创建一个结构体,结构体中的属性为要绑定的视图列

    public struct MyViewKey
    {
        [Persistent("Name")]
        public string Name;
        [Persistent("PhoneCode")]
        public string PhoneCode;
        [Persistent("Street")]
        public string Street;
        [Persistent("City")]
        public string City;
        [Persistent("FullAddress")]
        public string FullAddress;
    }

然后将这个结构体当成是Persistent类的KEY

 

    [Persistent("TestView")]          //TestView为视图名
    public class MyView : XPLiteObject {
    [Key, Persistent]
    public MyViewKey Key;

    public string Name{ get { return Key.Name; } }
    public string PhoneCode { get { return Key.PhoneCode; } }
    public string Street { get { return Key.Street; } }
    public string City { get { return Key.City; } }
    public string FullAddress { get { return Key.FullAddress; } }
}

这样就完成了

用到的视图Sql:

SELECT dbo.Country.Name, dbo.Country.PhoneCode, dbo.Address.Street, dbo.Address.City,
      dbo.Address.FullAddress
FROM dbo.Address INNER JOIN
      dbo.Country ON dbo.Address.Country = dbo.Country.Oid

Address:

CREATE TABLE [dbo].[Address] (
 [Street] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
 [City] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
 [StateProvince] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
 [ZipPostal] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
 [FullAddress] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
 [OptimisticLockField] [int] NULL ,
 [GCRecord] [int] NULL ,
 [OID] [int] IDENTITY (1, 1) NOT NULL ,
 [Country] [int] NULL
) ON [PRIMARY]

Country:

CREATE TABLE [dbo].[Country] (
 [Oid] [int] IDENTITY (1, 1) NOT NULL ,
 [Name] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
 [PhoneCode] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
 [OptimisticLockField] [int] NULL ,
 [GCRecord] [int] NULL
) ON [PRIMARY]
GO


 

posted @ 2008-11-13 13:33  丁守庆  阅读(915)  评论(1编辑  收藏  举报
专业成就价值