entity-framework-5

Is there a plural issue for models database context y to ies in mvc4 EF

我怕爱的太早我们不能终老 提交于 2019-12-11 02:14:09
问题 I keep getting error when I try to access a model from an edit or details action. The model backing the 'InjuriesContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269). First I tried adding a migration even though I was sure I hadn't changed anything. Still recieved the same error after an update-database. Then I removed all the migrations and the database and started a clean

Custom ValidationContext for EF?

不想你离开。 提交于 2019-12-11 01:46:27
问题 I'm using EF as my dataprovider to save and validate my items. I have some custom validation logic which needs access to other services or items. I know the ValidationContext class supplies these options. My question is how can I get my own validation context with an service provider or item to EF? When I implement the IValidateObject interface on my POCO entity I get an instance of the validation context, but where can I make sure my own ValidationContext is used instead of the EF default

Map weak entity by using Code first

我的未来我决定 提交于 2019-12-11 00:49:07
问题 Hi I have developed model that works perfectly for me, now I want to map it to database using EntityFramework, here is a part of it: public class Product { public int Id { get; set; } public string Name { get; set; } public virtual ProductType Type { get; set; } } public class Supplier { public int Id { get; set; } public string OIB { get; set; } public string Name { get; set; } } public class SupplierProduct { public double Price { get; set; } public string SupplierMark { get; set; } public

ObjectContext.Translate - Use different property names

时光怂恿深爱的人放手 提交于 2019-12-10 23:52:04
问题 I am using Entity Framework and calling a stored procedure as described here: http://msdn.microsoft.com/en-us/data/jj691402.aspx under "Accessing Multiple Result Sets with Code" After executing the stored procedure I am using the ObjectContext.Translate method to get my results into a data contract object, which requires that the data contract properties match up to the data returned. Is there any way I can use different property names, yet still have the Translate method map them correctly?

When using Attach in EF, is it possible to not overwrite properties I haven't Updated?

痞子三分冷 提交于 2019-12-10 22:06:26
问题 I'm updating an existing entity by attaching it to my data context like this: var updatedDocumentState = new AccDocumentState() { Id = accDocumentState.Id, IsDocumentary = accDocumentState.IsDocumentary, IsEditable = accDocumentState.IsEditable, IsRecursive = accDocumentState.IsRecursive, Title = accDocumentState.Title, Reportable = accDocumentState.Reportable, }; context.AccDocumentStates.Attach(updatedDocumentState); context.ObjectStateManager.ChangeObjectState(updatedDocumentState, System

Selective disabling of lazy loading with Database First method

六眼飞鱼酱① 提交于 2019-12-10 19:15:44
问题 I am not interested in disabling lazy loading for the entire context. I want only to selectively disable lazy loading for a few key navigational properties. With the Code First method, I understand how to selectively disable lazy loading: public virtual Person Requestor { get; set; } //lazy loading enabled ... public Person Requestor { get; set; } //lazy loading disabled However with the Database First method, this is code generated from a template so this modification is going to be lost on

DRY Entity Framework Search Call

混江龙づ霸主 提交于 2019-12-10 19:03:47
问题 I have an Entity Framework (v5.0) DbContext called Entities that is auto-generated by the framework (I think my design pattern is Database First). I have this search command (shown in the snippet below) that I am calling throughout the application. I want to DRY up my controller code and re-factor this into a method call. using (var db = new Entities()) { DateTime now = DateTime.Today; var activeEvents = db.Events.Where( b => !b.removed && b.start_date <= now && b.end_date >= now ); } Example

Linq Dynamically append Where clauses with OR

纵饮孤独 提交于 2019-12-10 17:59:48
问题 I've been trying to build a linq query with dynamically added where clauses. I have a web page with a bunch of checkboxes that are selected to correspond to which fields you want to search: What I have so far is the following: //This calls a select from table to construct the query which the where clauses will be added to IQueryable<AutoCompleteRestultDto> query = GetAutocompleteResults(); if (FirstName == true || AllFields == true) { Expression<Func<AutoCompleteRestultDto, bool>>

Is it possible to enable relationship fixup when change tracking is disabled but proxies are generated

纵饮孤独 提交于 2019-12-10 17:56:41
问题 I have entities which form a tree relationships. class MyEntity { public int Id {get;set;} public int ParentId {get;set;} public virtual MyEntity Parent {get;set;} public virtual ICollection<MyEntity> Children {get;set;} } When these entities are called without AsNoTracking() relationships are fixed up. var entities = MyEntitiesSet.ToList(); All navigation properties and collections are set. However if AsNoTracking() is called: var entities = MyEntitiesSet.AsNoTracking.ToList(); no navigation

how to stop dbentityentry.currentvalues.setvalues trying to change entitykey value

和自甴很熟 提交于 2019-12-10 17:41:57
问题 I am using the following code to update an entity object with the new information gathered from the my code. I am using Entity Framework 5 . I use the following extension method (as a alternative to the reattach code I used to use in EF4): public static void ApplyValues(this object currentObject, object sourceObject, System.Data.Entity.DbContext obj) { obj.Entry(currentObject).CurrentValues.SetValues(sourceObject); } The problem is that when this method is called the SetValues method tries to