1

I have an Stored Procedure in SQL Server 2012:

CREATE procedure [dbo].[GetEmailThread]
(
@id int
)
AS
SELECT e.Id, e.Created, e.MailFrom, e.MailTo, e.Body, e.Sended, ip.Ip, e2.Sended as ReplySended, e2.Body as ReplyBody, e2.Id as ReplyId
FROM Emails e 
LEFT JOIN IpAddress ip ON (ip.Id = e.IpId)
LEFT JOIN Emails e2 ON (e.Id = e2.ParentEmailId)
WHERE e.RealtyId = @id
ORDER BY e.Sended, ReplySended

Definition of Email Table:

CREATE TABLE [dbo].[Emails](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Created] [datetime] NOT NULL,
    [MailFrom] [nvarchar](100) NOT NULL,
    [MailTo] [nvarchar](500) NOT NULL,
    [Subject] [nvarchar](500) NULL,
    [Body] [nvarchar](max) NULL,
    [Sended] [datetime] NULL,
    [Ip] [varchar](15) NULL,
    [ReplyTo] [nvarchar](100) NULL,
    [IpId] [int] NULL,
    [RealtyId] [int] NULL,
    [ParentEmailId] [int] NULL,
    [IsBodyHtml] [bit] NOT NULL CONSTRAINT [DF_Emails_IsBodyHtml]  DEFAULT ((0)),

And EntityFramework model in C#. Whenever I right-click in Visual Studio Model Browser to this EntityFramework model and choose the menu "Update Model from Database", the model gets updated, but the field MailTo in GetEmailThread_Result is always missing.

I need to add it manually to the model GetEmailThread_Result.cs to get it working.

Why? Why this? I cannot see anything special in this field. Why not MailFrom?

Tomas Kubes
  • 23,880
  • 18
  • 111
  • 148
  • You can check whether you are pointing to correct database in web.config.It sometimes happens that we are trying to update EDMX file but it not updating correctly and reason we found out is that we are doing changes in one database and EDMX is using other database. – Sagar Shirke Nov 08 '15 at 10:06
  • I have checked the connection string and it is correct. Furthermore it is the right database, because if add new field, I can see it in this EntityFramework model. All other changes are updated except this field. – Tomas Kubes Nov 08 '15 at 10:20
  • Is it possible for you to use elias column name for this column , but non standard name (not similar to probable keyowrd) like e.MailTo as MailTo_new – Sagar Shirke Nov 08 '15 at 10:21
  • This does not work either. I tried add e.MailTo as MailTo2 – Tomas Kubes Nov 08 '15 at 10:36

1 Answers1

0

The solution was to manually edit EF files in the project as they were corrupted, for details see Updating Entity Framework Model

Community
  • 1
  • 1
Tomas Kubes
  • 23,880
  • 18
  • 111
  • 148