我们首先使用EF 3.5,数据库。 我更新了我的视图后,收到了下一条错误消息:
错误1错误3002:从第866行开始映射片段中的问题: 表vPendingOrders键的潜在运行时违规 (vPendingOrders.AccountId,vPendingOrders.AccountName, vPendingOrders.ApplicationModeTypeId, vPendingOrders.CampaignWorkflowId,vPendingOrders.EndDate, vPendingOrders.HiddenInGeneralList,vPendingOrders.HiddenInOwnerList, vPendingOrders.InstanceId,vPendingOrders.OrgId, vPendingOrders.StartDate,vPendingOrders.TotalBudget):列 (vPendingOrders.CampaignWorkflowId,vPendingOrders.InstanceId, vPendingOrders.OrgId,vPendingOrders.AccountId, vPendingOrders.AccountName,vPendingOrders.TotalBudget, vPendingOrders.StartDate,vPendingOrders.EndDate, vPendingOrders.HiddenInGeneralList,vPendingOrders.HiddenInOwnerList, vPendingOrders.ApplicationModeTypeId)映射到EntitySet vPendingOrders的属性(vPendingOrders.CampaignWorkflowId, vPendingOrders.InstanceId,vPendingOrders.OrgId, vPendingOrders.AccountId,vPendingOrders.AccountName, vPendingOrders.TotalBudget,vPendingOrders.StartDate, vPendingOrders.EndDate,vPendingOrders.HiddenInGeneralList, vPendingOrders.HiddenInOwnerList, vPendingOrders.ApplicationModeTypeId)在概念方面,但他们 不要形成EntitySet的关键属性(vPendingOrders.AccountId, vPendingOrders.AccountName,vPendingOrders.ApplicationModeTypeId, vPendingOrders.CampaignWorkflowId,vPendingOrders.EndDate, vPendingOrders.HiddenInGeneralList,vPendingOrders.HiddenInOwnerList, vPendingOrders.InstanceId,vPendingOrders.OrgId, vPendingOrders.SalesRep,vPendingOrders.StartDate, vPendingOrders.TotalBudget)。
如您所见,没有我的新文件FullName,Email和ContactId
视图如下所示:
CREATE VIEW [dbo].[vPendingOrders]
AS
SELECT TOP (100) PERCENT wf.CampaignWorkflow.CampaignWorkflowId, wf.CampaignWorkflow.InstanceId, dbo.vCampaigns.OrgId, wf.CampaignWorkflow.CampaignId,
dbo.vCampaigns.AccountId, wf.CampaignWorkflow.HasProposalReview, wf.CampaignWorkflow.HasMediaReview, wf.CampaignWorkflow.HasTraffickingEnabled,
dbo.vCampaigns.AccountName, wf.CampaignWorkflow.HasAuthorizedCreditCard, wf.CampaignWorkflow.HasAppliedForCredit, wf.CampaignWorkflow.HasDrops,
dbo.vCampaigns.TotalBudget, wf.CampaignWorkflow.StateMessage, dbo.vCampaigns.StartDate, dbo.vCampaigns.EndDate, dbo.vCampaigns.OwnerId,
dbo.vCampaigns.OwnerType, dbo.vCampaigns.HiddenInGeneralList, dbo.vCampaigns.HiddenInOwnerList, wf.CampaignWorkflow.ApplicationModeTypeId,
dbo.vCampaigns.SalesRep, dbo.vCampaigns.AdvertiserName,
-- new values
dbo.vCampaigns.FullName, dbo.vCampaigns.Email, dbo.vCampaigns.ContactId
FROM wf.CampaignWorkflow INNER JOIN
dbo.vCampaigns ON wf.CampaignWorkflow.CampaignId = dbo.vCampaigns.CampaignId
ORDER BY wf.CampaignWorkflow.CampaignWorkflowId DESC
此外,我只是尝试将现有列添加为别名(重复):dbo.vCampaigns.AdvertiserName 下一个第24列\属性的结果是相同的 - 错误3002
在该字段的属性中,EntityKey为false且Nullable为true。
我还在这里添加一个视图,我从中获取我的值:
SELECT cam.Campaign.CampaignId, cam.Campaign.OrgId, cam.Campaign.OwnerId, cam.Campaign.AccountId,
-- here they are
cam.Campaign.ContactId, SalesRep.FullName, SalesRep.Email,
cam.Campaign.AgencyId,
cam.Campaign.CampaignName, Advertiser.AccountName, Agency.AccountName AS AgencyName, cam.CampaignStatus.Code AS Type,
cam.Campaign.OwnerType, cam.Campaign.StartDate, cam.Campaign.EndDate, dbo.fnGetCampaignRunStatus(cam.Campaign.CampaignId, NULL)
AS Status, wf.CampaignWorkflow.StateMessage, wf.CampaignWorkflow.CampaignWorkflowId, cam.Campaign.TotalBudget,
cam.Campaign.HiddenInGeneralList, cam.Campaign.HiddenInOwnerList, cam.Campaign.Note,
CASE WHEN wf.CampaignWorkflow.ApplicationModeTypeId = 2 THEN CASE WHEN SalesRep.ContactId IS NULL
THEN Owner.FullName ELSE SalesRep.FullName END ELSE CASE WHEN SalesRep.ContactId IS NULL
THEN 'N/A' ELSE SalesRep.FullName END END AS SalesRep, CASE WHEN wf.CampaignWorkflow.ApplicationModeTypeId IS NULL
THEN 1 ELSE wf.CampaignWorkflow.ApplicationModeTypeId END AS ApplicationModeTypeId,
con.CustomListItem.CustomListItemName AS AdvertiserName, cam.Campaign.ClientOrderId
FROM cam.Campaign INNER JOIN
org.Account AS Advertiser ON cam.Campaign.AccountId = Advertiser.AccountId INNER JOIN
cam.CampaignStatus ON cam.Campaign.CampaignStatusId = cam.CampaignStatus.CampaignStatusId INNER JOIN
con.Contact AS Owner ON cam.Campaign.OwnerId = Owner.ContactId LEFT OUTER JOIN
con.CustomListItem ON cam.Campaign.AdvertiserId = con.CustomListItem.CustomListItemId LEFT OUTER JOIN
wf.CampaignWorkflow ON cam.Campaign.CampaignId = wf.CampaignWorkflow.CampaignId LEFT OUTER JOIN
org.Account AS Agency ON cam.Campaign.AgencyId = Agency.AccountId AND cam.Campaign.AgencyId = Agency.AccountId LEFT OUTER JOIN
con.Contact AS SalesRep ON cam.Campaign.SalesRepId = SalesRep.ContactId
答案 0 :(得分:0)
原因是EF模型更新操作的奇怪更新结果。 SaleRep in view(数据库)仍然是一个键,但在模型视图中,它是从一组键中自动删除的。但不是到处都是别的...... 所以解决方案 - 将实体键设置为False并将Nullable设置为True不适用于新字段,但适用于SalesRep