首页 新闻 搜索 专区 学院

EF使用特性映射,生成的SQL多出字段是怎么回事,执行就爆 列名 'lockBrand_Id' 无效

0
悬赏园豆:20 [已解决问题] 解决于 2016-05-26 09:53

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using SolidUtil;

namespace SolidDB
{
[Table("tOrderInfo", Schema = "dbo")]
public class OrderInfo : DBModelBase
{
public OrderInfo(){}

#region 普通属性

[Key]
[Column("order_id")]
public string Id { get; set; }

[Column("cust_name")]
public string CustName { get; set; }

[Column("cust_phone")]
public string CustPhone { get; set; }

[Column("cust_address")]
public string CustAddress { get; set; }

[Column("address_x")]
public string AddressX { get; set; }

[Column("address_y")]
public string AddressY { get; set; }

[Column("fault_description")]
public string FaultDescription { get; set; }

[Column("create_date")]
public Nullable<DateTime> CreateDate { get; set; }

/// <summary>
/// 预约时间,紧急程度为预约时才有意义
/// </summary>
[Column("reserve_time")]
public Nullable<DateTime> ReserveTime { get; set; }

[Column("get_date")]
public Nullable<DateTime> GetDate { get; set; }

[Column("done_date")]
public Nullable<DateTime> DoneDate { get; set; }


[Column("account_date")]
public Nullable<DateTime> AccountDate { get; set; }


/// <summary>
/// 锁匠总费用,计算列
/// </summary>
[Column("price")]
public decimal Price { get; set; }

[Column("que_price")]
public decimal QuePrice { get; set; }

/// <summary>
/// 锁匠基础费用
/// </summary>
[Column("base_price")]
public decimal BasePrice { get; set; }


[Column("done_address_x")]
public string Done_AddressX { get; set; }

[Column("done_address_y")]
public string Done_AddressY { get; set; }

[Column("remark")]
public string Remark { get; set; }

[Column("lock_count")]
public int LockCount { get; set; }

/// <summary>
/// 对商家费用
/// </summary>
[Column("dealer_price")]
public decimal DealerPrice { get; set; }

/// <summary>
/// 对商家基础费用
/// </summary>
[Column("base_dealer_price")]
public decimal BaseDealerPrice { get; set; }

[Column("que_dealer_price")]

public decimal QueDealerPrice { get; set; }

/// <summary>
/// 空跑次数1,需要测量,
/// </summary>
[Column("run_empty")]
public int? RunEmpty { get; set; }

/// <summary>
/// 是否需要测量OrderOptionManager.Measure = "000087";
/// </summary>
[Column("measure")]
public string Measure { get; set; }

/// <summary>
/// 是否需要改造OrderOptionManager.Refitting = "000088";
/// </summary>
[Column("refitting")]
public string Refitting { get; set; }

[Column("verify_code")]
public string VerifyCode { get; set; }
#endregion

#region 外键

#region 紧急程度
/// <summary>
/// 紧急程度
/// </summary>
[Column("dim_urgent")]
// [NotMapped]
public string DimUrgent { get; set; }

public Dim Urgent(EFContext ef) {
if (!urgentIsLoad)
{
urgent = ef.Find<Dim>(DimUrgent);
urgentIsLoad = true;
}
return urgent;
}
Dim urgent { get; set; }
bool urgentIsLoad;
#endregion

#region 门窗材质
[Column("material_quality")]
public string MaterialId { get; set; }
public Dim Material(EFContext ef)
{
if (!materialIsLoad) {
material = ef.Find<Dim>(MaterialId);
materialIsLoad = true;
}
return material;
}

Dim material { get; set; }

bool materialIsLoad { get; set; }
#endregion

#region 锁具品牌
[Column("dim_lock_brand")]
// [NotMapped]
public string DimLockBrand { get; set; }

public Dim LockBrand(EFContext ef) {
if (!lockBrandIsLoad) {
lockBrand = ef.Find<Dim>(DimLockBrand);
lockBrandIsLoad = true;
}
return lockBrand;
}
Dim lockBrand { get; set; }
bool lockBrandIsLoad;
#endregion

#region 锁具类型
[Column("dim_lock_type")]

// [NotMapped]
public string DimLockType { get; set; }
public Dim LockType(EFContext ef ) {
if (!lockTypeIsLoad)
{
lockType = ef.Find<Dim>(DimLockType);
lockTypeIsLoad = true;
}
return lockType;
}
Dim lockType { get; set; }
bool lockTypeIsLoad;
#endregion

#region 服务类型
[Column("dim_server_type")]
public string DimServerType{get;set; }

public Dim ServerType(EFContext ef) {
if (!serverTypeIsLoad) {
serverType = ef.Find<Dim>(DimServerType);
serverTypeIsLoad = true;
}
return serverType;
}
Dim serverType;
bool serverTypeIsLoad;
#endregion

#region 订单状态
[Column("dim_order_state")]
//[NotMapped]
public string DimOrderState { get; set; }

public Dim OrderState(EFContext ef){
if (!orderStateIsLoad)
{
orderState = ef.Find<Dim>(DimOrderState);
orderStateIsLoad = true;
}
return orderState;
}
Dim orderState { get; set; }
bool orderStateIsLoad;
#endregion

#region 客户信息
[Column("cust_id")]
public string CustId { get; set; }

public virtual CustInfo CustInfo(EFContext ef) {
if (!custInfoIsLoad)
{
custInfo = ef.Find<CustInfo>(CustId);
custInfoIsLoad = true;
}
return custInfo;
}

CustInfo custInfo;
bool custInfoIsLoad;
#endregion

#region 发单人
[Column("create_user_id")]
public string SendUserId { get; set; }//发单人

public virtual SysUser SendUser(EFContext ef) {
if (!sendUserIsLoad) {
sendUser = ef.Find<SysUser>(SendUserId);
sendUserIsLoad = true;
}
return sendUser;
}
SysUser sendUser;
bool sendUserIsLoad;
#endregion


#region 接收人
[Column("receive_user_id")]
public string ReceiveUserId { get; set; }//接单人

public virtual SysUser ReceiveUser(EFContext ef) {
if (!receiveUserIsLoad)
{
receiveUser = ef.Find<SysUser>(ReceiveUserId);
receiveUserIsLoad = true;
}
return receiveUser;
}
SysUser receiveUser;
bool receiveUserIsLoad;

#endregion

#region 区域
[Column("area_id")]
public string AreaId { get; set; }
public virtual Area Area(EFContext ef) {
if (!areaIsLoad)
{
area = ef.Find<Area>(AreaId);
areaIsLoad = true;
}
return area;
}

Area area;
bool areaIsLoad;
#endregion

#region 工单来源
[Column("from_commercial_user")]
public int? CommercialUserId { get; set; }
public virtual CommercialUser CommercialUser(EFContext ef) {
if (!commercialUserIsLoad)
{
commercialUser = ef.Find<CommercialUser>(CommercialUserId);
commercialUserIsLoad = true;
}
return commercialUser;
}
CommercialUser commercialUser;
bool commercialUserIsLoad;
#endregion

#region 负责人
[Column("main_responsible_user")]
public string MainResponsibleUserId { get; set; }

public virtual SysUser MainResponsibleUser(EFContext ef) {
if (!mainResponsibleUserIsLoad) {
mainResponsibleUser = ef.Find<SysUser>(MainResponsibleUserId);
mainResponsibleUserIsLoad = true;
}
return mainResponsibleUser;
}

SysUser mainResponsibleUser;
bool mainResponsibleUserIsLoad;
#endregion

#endregion

#region 导航

#region 工单流转
//[InverseProperty("OrderInfo")]
public virtual ICollection<OrderFlow> OrderFlows(EFContext ef) {
if (!orderFlowsIsLoad)
{
orderFlows = ef.FindAll<OrderFlow>(o => o.OrderId == Id);
orderFlowsIsLoad = true;
}
return orderFlows;
}
ICollection<OrderFlow> orderFlows;
bool orderFlowsIsLoad;
#endregion

//[InverseProperty("OrderInfo")]
//public virtual ICollection<OrderPush> OrderPushs { get; set; }

#region 工单回访
//[InverseProperty("OrderInfo")]
public virtual ICollection<OrderReturnVisit> OrderReturnVisits(EFContext ef) {
if (!orderReturnVisitsIsLoad)
{
orderReturnVisits = ef.FindAll<OrderReturnVisit>(o => o.OrderId == Id);
orderReturnVisitsIsLoad = true;
}
return orderReturnVisits;
}
ICollection<OrderReturnVisit> orderReturnVisits;
bool orderReturnVisitsIsLoad;
#endregion

#region 工单图片
//[InverseProperty("OrderInfo")]
public virtual ICollection<OrderPicture> OrderPictures(EFContext ef)
{

if (!orderPicturesIsLoad)
{
orderPictures = ef.FindAll<OrderPicture>(o => o.OrderId == Id);
orderPicturesIsLoad = true;
}
return orderPictures;
}

ICollection<OrderPicture> orderPictures;
bool orderPicturesIsLoad;
#endregion

#region 工单问题
//[InverseProperty("OrderInfo")]
public virtual ICollection<OrderQue> OrderQues(EFContext ef) {
if (!orderQuesIsLoad)
{
orderQues = ef.FindAll<OrderQue>(o=>o.OrderId==Id);
orderQuesIsLoad = true;
}
return orderQues;
}

ICollection<OrderQue> orderQues;
bool orderQuesIsLoad;
#endregion

#region 工单进度
//[InverseProperty("OrderInfo")]
public virtual ICollection<OrderProcess> OrderProcesss(EFContext ef) {
if (!orderProcesssIsLoad)
{
orderProcesss = ef.FindAll<OrderProcess>(o=>o.OrderId==Id);
orderProcesssIsLoad = true;
}
return orderProcesss;
}

ICollection<OrderProcess> orderProcesss;
bool orderProcesssIsLoad;
#endregion
#endregion

static PKUtil timePK = new PKUtil();
public override string GetKey(EFContext ef)
{
lock (timePK)
{
string pk;
OrderInfo orderInfo;
do
{
pk = timePK.GetTimeIdentification();
orderInfo = ef.Find<OrderInfo>(pk);
if (orderInfo == null) { break; }

} while (true);

return pk;
}
}
}
}

EF
问题补充:

[Extent1].[lockBrand_Id] AS [lockBrand_Id], 
[Extent1].[lockType_Id] AS [lockType_Id], 
[Extent1].[orderState_Id] AS [orderState_Id], 
[Extent1].[urgent_Id] AS [urgent_Id]

 

这四个字段,特性里根本没有,却生成了,这是怎么回事

青楼满座的主页 青楼满座 | 初学一级 | 园豆:2
提问于:2016-05-24 16:43
< >
分享
最佳答案
0

Dim lockBrand { get; set; }

看你entity里面有这个呀。

收获园豆:20
czd890 | 大侠五级 |园豆:9531 | 2016-05-25 12:50

这个是私有的,并且没有使用特性标记,EF居然也给生产了SQL我仔细对比过,设为字段就ok了,不能设为属性,

青楼满座 | 园豆:2 (初学一级) | 2016-05-26 09:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册