Это может звучать странно, но у меня есть сущность:
public class Center : Archive
{
public int Id { get; set; }
[MaxLength(50)] public string ExternalId { get; set; }
[Required] [MaxLength(150)] public string Name { get; set; }
[MaxLength(255)] public string Description { get; set; }
[MaxLength(50)] public string Address1 { get; set; }
[MaxLength(50)] public string Address2 { get; set; }
[MaxLength(50)] public string Address3 { get; set; }
[MaxLength(50)] public string Address4 { get; set; }
[MaxLength(10)] public string PostCode { get; set; }
[MaxLength(100)] public string CollectionPointContact { get; set; }
[MaxLength(50)] public string CollectionPointTelephone { get; set; }
[MaxLength(50)] public string CollectionPointFax { get; set; }
[MaxLength(255)] public string CollectionPointEmail { get; set; }
[NotMapped] public int Due { get; set; }
[NotMapped] public int Today { get; set; }
[NotMapped] public int Expected { get; set; }
[NotMapped] public int Planned { get; set; }
public int CompanyId { get; set; }
public Company Company { get; set; }
public IList<Collection> Collections { get; set; }
}
При перечислении, редактировании, создании и т. Д. Свойства [NotMapped]
не должны отображаться в базе данных.
Но у меня есть хранимая процедура, которая заполняет эти свойства:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[ListCentersByCompany]
@CompanyId [int]
AS
BEGIN
select ce.*,
SUM(CASE WHEN co.PlannedCollectionDate < CONVERT(DATE, GETDATE()) THEN 1 ELSE 0 END) AS Due,
SUM(CASE WHEN co.PlannedCollectionDate = CONVERT(DATE, GETDATE()) THEN 1 ELSE 0 END) AS Today,
SUM(CASE WHEN co.PlannedCollectionDate = DATEADD(DAY, 1, CONVERT(DATE, GETDATE())) THEN 1 ELSE 0 END) AS Expected,
SUM(CASE WHEN co.PlannedCollectionDate > DATEADD(DAY, 1, CONVERT(DATE, GETDATE())) THEN 1 ELSE 0 END) AS Planned
from Centers ce join
Collections co
on ce.Id = co.CenterId
WHERE ce.CompanyId = @CompanyId
group by
ce.Id,
ce.ExternalId,
ce.Name,
ce.Description,
ce.Address1,
ce.Address2,
ce.Address3,
ce.Address4,
ce.PostCode,
ce.CollectionPointContact,
ce.CollectionPointEmail,
ce.CollectionPointFax,
ce.CollectionPointTelephone,
ce.CompanyId,
ce.CreatedById,
ce.ModifiedById,
ce.DateCreated,
ce.DateModified
END
EntityFramework не знает, чтобы отобразить их, но когда я использую свой SPROC, я бы хотел, чтобы они отображались.
Это возможно? Я понимаю, что мог бы просто создать новую модель и использовать ее вместо этого, но я хочу знать, есть ли что-то более простое?