entity-framework-4

Entity Framework hides inherited member Warning

被刻印的时光 ゝ 提交于 2019-12-12 21:24:42
问题 I have For Example Product and a ProductDetail Table. Where in Model Product is a base class for ProductDetail. There is a ProductName in ProductDetail. Everything is working fine but I wanted to know that why the EF is giving me this warning and how to remove this. I tried updating Designer.cs with a new keyword was just keen to see what happens but it removes it as soon as it is compiled. Googled it out but did not find any relevant information. So m here asking a question if anybody knows

Why won't EF4 generate a method to support my Function Import?

陌路散爱 提交于 2019-12-12 20:59:57
问题 I have a stored proc in my database which returns an integer. I added a Function Import to my model. This appears in the EDMX file: <Function Name="GetTotalEntityCount" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo" /> However, no method actually gets generated for this. It should be top level, right? using (MyContext context = new MyContext()) { context.MyMethodShouldBeRightHere(); } Nothing appears

Finding the Changeset in Entity Framework

邮差的信 提交于 2019-12-12 20:57:49
问题 I am using EF4 repositories in a ASP.NET MVC3/WCF application. I am using the Unit of Work pattern to apply changes to the database One of the user requirements is to create a ticket/email with a list of changes to the entity. Is there a way I can detect only the changed properties on an entity in the following function? public void UpdateTrackedEntity<T>(T modifiedEntity) where T : class { var set = CreateObjectSet<T>(); set.ApplyCurrentValues(modifiedEntity); } 回答1: Yes there is a way:

Entity Framework - Saving child entities on update

流过昼夜 提交于 2019-12-12 20:49:42
问题 I have an Invoice entity and it has child InvoiceLog entities. When I first create an Invoice and add its InvoiceLog entities and save, it works fine. However, if I then edit the Invoice and try to add additional InvoiceLog entities, it completely ignores the new InvoiceLog entities and doesn't save them at all. Any ideas what I'm doing wrong? //POST: /Secure/Invoices/Save/ [AcceptVerbs(HttpVerbs.Post)] public ActionResult Save(Invoice invoice) { invoice.UpdateDate = DateTime.Now; invoice

Entity Framework query table name dynamically based on input parameter

感情迁移 提交于 2019-12-12 20:34:10
问题 I have been working in a project which uses Entity Framework as the ORM data model to connect to the SQL database and retrieve data. Now the basic query which is used to retrieve data is like this ProjectDataContext dataContext = new ProjectDataContext(); var result = (from project in dataContext.Projects select project).ToList(); Or in lambda List<Project> lstprojects = dataContext.Projects.Take(10); Now I would like to pass the table name dynamically based on some input parameter. How can I

Ninject MVC 2, EF 4, AutoMapper - ObjectContext has been disposed

偶尔善良 提交于 2019-12-12 18:28:29
问题 Completely revised: Okay, I'm using Ninject with the MVC 2 extension as my DI container, and AutoMapper as my entity <--> view model mapper. I'm getting an 'ObjectContext is disposed' error in my view model -> entity mapping. My code is below. Ninject bindings: public class DIModule : NinjectModule { public override void Load() { this.Bind<HGEntities>().ToSelf().InRequestScope(); this.Bind<IArticleRepository>().To<HGArticleRepository>().InRequestScope(); this.Bind<IGameRepository>().To

Save disconnected object in entity framework 4

自闭症网瘾萝莉.ら 提交于 2019-12-12 18:19:30
问题 in EF1, i couldn't just update an object that was constructed (with the right id) outside the scope of the ObjectContext. Is there a new way in EF4? Can i just add it to the context (context.AddOrder(order)) (where context is an instance of my ObjectContext) and 'it' sees that it has an id and updates it? It's non-poco so my objects derive from EntityObject 回答1: Use the Attach method instead. It is designed for disconnected objects. 回答2: If it's a brand new object then you should use either

FormView with EntityDataSource and DropDownList gives “A property names '{0}' was not found on the entity …”

最后都变了- 提交于 2019-12-12 18:00:55
问题 The problem: when I try to do an update using an EntityDataSource and a FormView that has an <asp:DropDownList> linking to another table, the page loads fine with the proper setting, but on update I get this error message: A property named 'Vendor.VendorId' was not found on the entity during an insert, update, or delete operation. Check to ensure that properties specified as binding expressions are available to the data source. The environment and code: using Visual Studio 2010, Entity

How to force only one transaction within multiple DbContext classes?

可紊 提交于 2019-12-12 17:58:28
问题 Background: From another question here at SO I have a Winforms solution (Finance) with many projects (fixed projects for the solution). Now one of my customers asked me to "upgrade" the solution and add projects/modules that will come from another Winforms solution (HR). I really don't want to keep these projects as fixed projects on the existing finance solution. For that I'm trying to create plugins that will load GUI, business logic and the data layer all using MEF. Question: I have a

EF4 Self referencing with association 0..1 -> 1

ⅰ亾dé卋堺 提交于 2019-12-12 16:59:31
问题 There's a lot of reading on self referencing problems, but I can't seem to find an answer to my question. Say I have a Human (A), and I want A to have a partner, another Human(B). Naturally, it means that B has a partner in human A. How would you solve this? Ideally, I should only have to do: humanA.Partner = humanB; and humanB would automatically get humanA as a partner. I would have thought I could create a Human enity, and add an Association, something like: End1 Entity: Human ,