Skip to main content

Posts

Showing posts with the label Entity Framework

How to view the SQL generated query by the Entity Framework

If we want to write log file of Entity Framework query in EF 6 we can follow this step Step 1: Open EDMX cs file and copy the code: protected override void OnModelCreating(DbModelBuilder modelBuilder) { Database.Log = (query) => Debug.Write(query); } Step 2 : write log on your Entity Framework query refauthrequests refauthEntity = EM_Refauthrequests.ConvertToEntity(vsspoAuditModel); _db.refauthrequests.Add(refauthEntity); _db.Database.Log = queryLog => { Debug.Print(queryLog); // Debug.Print will show the output on visual studio output window You can write log using queryLog value }; _db.SaveChanges(); If you set debugger you will see the output window

An error occurred while updating the entries. See the inner exception for details.

If you are using EF then you may get the error. This error is not specify where the error exactly occur in your table. To specify the error use this code & use debugger to see the exact error message. try { //Your code db = new FEDALIC_AGRI_DBEntities (); model.FarmerVillage = new Guid(village); model.FarmerThana = new Guid(thana); model.FarmerDistrict = new Guid(district); var _SET_FARMER_INFO = EMFermar.SetToModelObject(model); db.SET_FARMER_INFO.Add(_SET_FARMER_INFO); db.SaveChanges(); } catch (DbUpdateException e) { var innerEx = e.InnerException; while (innerEx.InnerException != null) innerEx = innerEx.InnerException; throw new Exception(innerEx.Message); } catch (DbEntityValidationException e...

WCF Ria doamin service in VS 2012

In VS – 2012 we can’t see the EDMX table for creating a domain service in Silverlight application. In order to utilize your Entity Framework model with WCF RIA Services, you must convert it to an 'ObjectContext' based model. This can be done using the following steps: Open your entity model in the designer (If needed, click in the "white space" of the designer to ensure no objects within the model are selected) In the Properties window, change the "Code Generation Strategy" from "None" to "Default" Delete the two ".tt" files that are adjacent to the model, with the assumption that you have not modified these files beyond their original state when the entity model was created. If you have modified these files, then customizations to your entity model will be lost. Rebuild the project After following those steps, you will be able to select your entity model's c...

Date range query in Entity framework

Entity Framework Date rang query is not same as like LINQ. You can try like this var events = this.coreDomainContext.Events.Where( e => EntityFunctions.TruncateTime(e.EventDate.Value) >= DateTime.Today && EntityFunctions.TruncateTime(e.EventDate.Value) <= EntityFunctions.TruncateTime(endPeriod)) .OrderByDescending(e => e.EventDate) .ToList(); For details you can See