locked
Designer.cs empty and AddObject error RRS feed

  • Question

  • I am learning entiry framework and following an example in Pro C#5.0 and the .NET 4.5 Framework Sixth edition aPress book page 947. It says to open Designer.cs and view the code. It mentions having code such as XXXEntities class. I see no code and only comments.

    // T4 code generation is enabled for model 'C:\temp\TestingEntityFrameworkLocal\TestingEntityFrameworkLocal\CoordTypeModel.edmx'.

    // To enable legacy code generation, change the value of the 'Code Generation Strategy' designer

    // property to 'Legacy ObjectContext'. This property is available in the Properties Window when the model

    // is open in the designer.


    // If no context and entity classes have been generated, it may be because you created an empty model but

    // have not yet chosen which version of Entity Framework to use. To generate a context class and entity

    // classes for your model, open the model in the designer, right-click on the designer surface, and

    // select 'Update Model from Database...', 'Generate Database from Model...', or 'Add Code Generation

    // Item...'.

    I do not see any other code.

    I have tried Build, Rebuild, Run Custom Tool (does nothing) and Update Model From Database within the Diagram.

    Nothing seems to work or generate any code.
    When I follow on from the book and code my Main (cosnole Application) to include

    using (CoordTypeEntities context = new CoordTypeEntities())
                {
                    try
                    {
                        context.CoordTypes.AddObject(new CoordType() { TypeOfCoord = "PeggingGPS", Description="",Rank=900 });
                        context.SaveChanges();
                    }

    I get an error onAddObject as System.Data.Entity.DbSet does not contain a definition for "AddObject'.

    Can someone please help me with what I am doing wrong.

    Thanks in advance.

    Tuesday, January 19, 2016 5:52 AM

Answers

  •  get an error onAddObject as System.Data.Entity.DbSet does not contain a definition for "AddObject'.

    Can someone please help me with what I am doing wrong.

    The book you are trying to use is outdated.

    It is using ObectContext and the AddObject() method is part of ObjectContext.

    EF 6 is using DBContext and it is using Add() as it's method to add an object.

    https://msdn.microsoft.com/en-us/data/jj729737.aspx

    Friday, January 22, 2016 1:25 PM

All replies

  • Hi Quentin.Samuelson,

    Thank you for posting in MSDN forum.

    This forum is discuss Visual Studio Setup and installation.
    As your issue is related to entity framework ,I help you move this case to Data Platform Development   ADO.NET Entity Framework and LINQ to Entities  forum for dedicated support.

    Thank you for your understanding.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

    Click HERE to participate the survey.

    Wednesday, January 20, 2016 7:24 AM
  •  get an error onAddObject as System.Data.Entity.DbSet does not contain a definition for "AddObject'.

    Can someone please help me with what I am doing wrong.

    The book you are trying to use is outdated.

    It is using ObectContext and the AddObject() method is part of ObjectContext.

    EF 6 is using DBContext and it is using Add() as it's method to add an object.

    https://msdn.microsoft.com/en-us/data/jj729737.aspx

    Friday, January 22, 2016 1:25 PM