标签:
EF版本:6+
MySql版本:5+
在MySql中创建表2张,分别是testWeigh和testOrderShip.表脚本如下所示:
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `testweigh`
-- ----------------------------
DROP TABLE IF EXISTS `testweigh`;
CREATE TABLE `testweigh` (
`LogisticsNo` varchar(50) NOT NULL,
PRIMARY KEY (`LogisticsNo`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of testweigh
-- ----------------------------
INSERT INTO `testweigh` VALUES (‘FF271237513CN‘);
和
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `testordership`
-- ----------------------------
DROP TABLE IF EXISTS `testordership`;
CREATE TABLE `testordership` (
`ShopCode` varchar(50) NOT NULL DEFAULT ‘‘,
`BillNo` varchar(50) NOT NULL DEFAULT ‘‘,
`LogisticsNo` varchar(50) DEFAULT NULL,
PRIMARY KEY (`ShopCode`,`BillNo`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of testordership
-- ----------------------------
INSERT INTO `testordership` VALUES (‘Default‘, ‘64909520666335‘, ‘FF271237513CN‘);
INSERT INTO `testordership` VALUES (‘Default‘, ‘64909520777335‘, ‘FF271237513CN‘);
INSERT INTO `testordership` VALUES (‘Default‘, ‘64909520888335‘, ‘FF271237513CN‘);
创建视图1张,视图脚本如下所示:
create view vtestorderweigh
as
select w.LogisticsNo,s.ShopCode,s.BillNo from testWeigh w left join testOrderShip s on w.LogisticsNo = s.LogisticsNo;
执行视图查询,得到如下结果:
l 创建EF实体类
l 通过EF获取数据
问题来了?为啥三条数据的BillNo值一样?查询视图中,值应分别是666,777,888
标签:
原文地址:http://www.cnblogs.com/xiyang1011/p/4275287.html