0

I have added a new table to the localDB called ChatLog where I store chat messages and I have created 3 stored procedures for the table.

I've been looking online on how to configure that table for Entity Framework but I can't find a solution that works for me, I've even tried the override work arounds but usually there's an error revolving around DbContext that's not pulled from services.

I'm new at this and don't really know what I should do, and as I said, tutorials arent really helping since I lack the knowledge.

could some one give me a hand here? the table looks like this:

Column      | type
----------------------------
SenderId    | nvarchar(256)
RecipientId | nvarchar(256)
Message     | ntext
Time        | date

I have tried writing this, but it doesn't work:

[Table("ChatLog")]
public class ChatMessage
{
    [Required]
    [Column("SenderId")]
    public string SenderId { get; set; }
    [Required]
    [Column("RecipientId")]
    public string RecipientId { get; set; }
    [Required]
    [Column("Message")]
    public string Message { get; set; }
    [Required]
    [Column("Time")]
    public DateTime Time { get; set; }
}

class ChatLogContext : DbContext
{

    public DbSet<ChatMessage> ChatMessages { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<ChatMessage>()
            .ToTable("ChatLog");
    }
}
2
  • which entity framework you are using Data First Approach or Model First Approach ? Commented Jul 8, 2016 at 18:36
  • I.. don't know. I made the table myself then realized I have to use EF to access the data.. so I would say, Data First Commented Jul 8, 2016 at 18:42

1 Answer 1

1

You have to update your .edmx file for apply database changes, Please follow the below steps to update your table :

To update the .edmx file when the database changes :

1) Open your .edmx file by simply clicking on.

2) When the .edmx file is opened then simply right click on select Update Model from Database.

The Update Model Wizard starts. If there is no database connection specified, the Choose Your Database Connection dialog box appears. Otherwise, the Choose Your Database Objects dialog box appears.

3) If the Choose Your Database Connection dialog box appears, specify a database connection. Otherwise, go to the next step.

4) Click the Add tab.

5) Expand the Tables, Views, and Stored Procedures nodes, and check the objects you want to add to the .edmx file.

6) Click Finish to update the .edmx file with the database changes.

after applying this you will get your desired Table in your .edmx file.

Hope it helps you.

Happy Coding :)

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

3 Comments

ok.. use this link for your refrence : c-sharpcorner.com/UploadFile/4923b7/…
AND I don't have ADO.NET Entity Data Model in my templates.. Everything else runs perfectly, as the users database fills up, but I can't to the bottom of that to see how it's connected
When I open the templates I only have ASP.NET, Clientside and Code as template categories.

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.