Question

I use entity framework in mvc razor. edmx does not accept a table with all allow nulls columns. When i update model from database the table is not getting added in entity framework.

USE [exampledb]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Table_1](
    [id] [int] NULL,
    [name] [varchar](50) NULL
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO
Was it helpful?

Solution

Well, Entity Framework needs a way for unique identification of each row in your table. Since in db design row identification is done through primary key (Entity Key in model), you need to add them to your table, otherwise you will have problems with adding your table to EF model. Sometimes entity can infer entity key automatically (for example, it often happens when you generating model from view). Also, for view, common way to overcome this problem is to use ISNULL statement.

But for table - you must have non-nullable identification field, better - primary key (to conform to db design patterns), in order this table to be added to your model.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top