Showing posts with label Entity Framework. Show all posts
Showing posts with label Entity Framework. Show all posts

3/18/19

entity framework commands


  1. Add-Migration 'to create database'
  2. Update-Database -----For example, suppose there are many migrations applied to the  database but you want to roll back to the first migration. Then execute the following command.
  3. update-database -TargetMigration:SchoolDB-v1

5/20/18

log DbEntityValidationException Exceptions

      catch (DbEntityValidationException ex)
                    {
                        foreach (var eve in ex.EntityValidationErrors)
                        {
                           responseBase.Message = string.Format(@"Entity of type \{0}\ in state \{1}\ has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State);
                            foreach (var ve in eve.ValidationErrors)
                            {
                                responseBase.Message= string.Format(@"- Property: \{0}\, Error: \{1}\", ve.PropertyName, ve.ErrorMessage);
                            }
                        }
                        throw;
                    }

6/15/16

How to bring two table from entity Framework

            var result = db.table1.Join(db.table2, r => r.Id, p => p.CountryId, (r, p) =>
                        new { r.Id, r.Name, p.CityId,p.CityName,p.CountryId });