0

I am trying to save value but passing object having one extra field in EF and in database table I do not have that field my code is,

        try
        {
            AgencyReports row = DB.AgencyReports.SingleOrDefault(p => p.Id == obj.Id);
            if (row != null)
            {

                row.Status = state;
                DB.SaveChanges();
                return true;
            }
        }
        catch (Exception ex)
        {

        }

AgencyReport has one extra field "Penalty" But in database it does not exsis. Is there any way to remore field from object without updating the entityframework ?

I have restriction not to change EF

hopes for your suggestion?

john derik
  • 65
  • 10
  • You can't tell EF to ignore a column without changing it's mapping or behaviour (like saying its a computed column). Either create the column on the database, refresh EF so it deletes the unexisting column or exclude the column explicitly by mapping all other columns on the entity's mapping. – EzLo Dec 20 '18 at 12:53
  • ok can I delete field directly from edmx diagram and its model class ? – john derik Dec 20 '18 at 13:07
  • Yes, but beware, you have to remove it from several places (I don't specifically remember how the edmx works internally). – EzLo Dec 20 '18 at 14:10
  • Use the [NotMapped] attribute on the "column" in your AgencyReports class. See here for a similar question with a very highly rated answer: https://stackoverflow.com/questions/10385248/ignoring-a-class-property-in-entity-framework-4-1-code-first – jdnew18 Dec 20 '18 at 15:23
  • @jdnw18 Solution mention in these posts are not working on EF 6 – john derik Dec 23 '18 at 15:38
  • @johnderik It looks like the issue with [NotMapped] not working in that post is probably due to stale .DLL references when upgrading between different versions of EF. See here: https://stackoverflow.com/questions/43628538/entity-framework-avoiding-notmapped-attribute-in-release-mode and here: https://stackoverflow.com/questions/25646756/upgrade-to-ef-6-1-1-makes-effect-of-notmapped-disappear and here: https://social.msdn.microsoft.com/Forums/en-US/2d682be0-daca-45c4-ad76-5885acc6004f/possible-bug-with-inheritance-and-notmapped?forum=adodotnetentityframework for help. – jdnew18 Dec 27 '18 at 20:02

0 Answers0