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


 

转载于:https://www.cnblogs.com/dingshouqing/articles/1332715.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值