1

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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

thankyou, So the example table which I provided cannot be added in entity ?
No. Best solution is to mark id as primary key (which automatically will make this column non-nullable), or to add one more column, like entity_id, which will be, for example, integer, autoincrement and primary key.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.