首先创建一个结构体,结构体中的属性为要绑定的视图列publicstructMyViewKey
{
[Persistent("Name")]publicstringName;
[Persistent("PhoneCode")]publicstringPhoneCode;
[Persistent("Street")]publicstringStreet;
[Persistent("City")]publicstringCity;
[Persistent("FullAddress")]publicstringFullAddress;
}
然后将这个结构体当成是Persistent类的KEY
[Persistent("TestView")]//TestView为视图名publicclassMyView : XPLiteObject {
[Key, Persistent]publicMyViewKey Key;publicstringName{get{returnKey.Name; } }publicstringPhoneCode {get{returnKey.PhoneCode; } }publicstringStreet {get{returnKey.Street; } }publicstringCity {get{returnKey.City; } }publicstringFullAddress {get{returnKey.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
引自:http://www.cnblogs.com/dingshouqing/articles/1332715.html