entity-framework-4

Problems using EF4.1 Code First with MVC3 and MySQL

巧了我就是萌 提交于 2019-12-24 08:38:11
问题 I am following this guide: http://www.asp.net/entity-framework/tutorials/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application So that is MVC3 with EF Code First and I am trying to use MySQL instead of SQLSERVER. So far I have downloaded the MySqlConnector/Net (and also Devart dotConnect). In my web.config I have added the following under <add name="ProjectContext" connectionString="Server=localhost; Database=project; Uid=root; Pwd=pass;" providerName="MySql.Data.MySqlClient"

How to auto-generate simple CRUD controllers and views in ASP.Net MVC 2 (VS2010) Entity Framework project?

旧巷老猫 提交于 2019-12-24 07:39:53
问题 I have a standard template "ASP.NET MVC 2 Web application" solution, an empty (meaning no data inserted, but with all tables etc. ready and waiting) SQL Server database, an Entity Framework 4 model (edmx). Is there a way to generate simple CRUD controllers and form views for all the entities in the model? 回答1: A buddy out there helped me with the answer - the answer is to use a "ASP.NET Dynamic Data Entities Web Application" instead of "ASP.NET MVC 2 Web Application" project template. The

EF CTP4 lazy loading not playing ball

旧时模样 提交于 2019-12-24 07:03:19
问题 I'm using the CTP4 code first EF framework, but I'm having problems getting lazy loading to work. Reading up on it, it should be simple, but it's just not public class Folder { public int Id { get; set; } public string Name { get; set; } public int? ParentFolderId { get; set; } public virtual IList<Folder> ChildFolders { get; set; } } In the model configuration: HasMany(f => f.ChildFolders).WithOptional().HasConstraint((child, folder) => child.ParentFolderId == folder.Id); However, when I do

Entity Framework 4 Partialy SaveChanges

隐身守侯 提交于 2019-12-24 06:47:44
问题 Lets say i have this: var entity = db.histories.GetWhere(x => x.Body == "MyBody").FirstOrDefault(); var entity2 = db.histories.GetWhere(x => x.Body == "MyBody2").FirstOrDefault(); entity.From = "lmao!"; entity2.From = "lmao2!"; now i know that to update i have to call db.SaveChanges(); my question is what if i want to update entity only and not entity2 ? is that even possible ? could be simple im not sure. thanks in advance. 回答1: Either get the 2 entities from separate contexts: var entity =

Creating a view of an entity

给你一囗甜甜゛ 提交于 2019-12-24 06:47:16
问题 Is it possible to create a view of an entity in entity framework without creating a view in DAL? i have a parent table named Receipt . Receipt can be active or inactive. if i implement IsActive as an attribute of the Receipt , there's a high risk of forgetting to attach .Where(r=>r.IsActive) to all Linq queries and high cost of adding it to previous codes. i tried to inherit a child DeletedReceipt with condition IsActive=false in model and add condition IsActive=true to Receipt (Parent).

Binding custom property in Entity Framework

夙愿已清 提交于 2019-12-24 05:28:22
问题 I have an employee entity in my EF model. I then added a class to the project to add a custom property public partial class Employee { public string Name { get { return string.Format("{0} {1}", this.FirstName, this.LastName); } } } On a aspx form (inside a FormView), I want to bind a DropDownList to the employee collection: <asp:Label runat="server" AssociatedControlID="ddlManagerId" Text="ManagerId" /> <asp:DropDownList ID="ddlManagerId" runat="server" DataSourceID="edsManagerId"

How can I implement Query Interception in a LINQ to Entities query? (c#)

北城以北 提交于 2019-12-24 04:53:54
问题 I'm trying to implement encrypted columns in EF4 and using the CTP5 features to allow simple use of POCO's to query the database. Sorry that this is a lot of words, but I hope the below gives enough to explain the need and the problem! So, bit of background, and my progress so far: The intention is that if you query the tables without using our DAL then the data is rubbish, but I don't want the developers to worry about if/when/how the data is encrypted. For simplicity, at this stage I'm

Entity Framework Error : The ObjectContext instance has been disposed and can no longer be used for operations that require a connection

萝らか妹 提交于 2019-12-24 04:34:15
问题 I am using Entity Framework with a business Later, DAL and a base Interface. I am inheriting the IDispose interface in my repository, I am getting the following error trying to get this list back. most of the examples I have come across suggest using IEnumerable and add .ToList() for the query and I have already as seen below. How can I get around this? This is working in other places where I have similar multiple related entity queries, I dont understand why im getting the error here? If

KeyValuePair from running Raw SQL query on Entity Framework

南笙酒味 提交于 2019-12-24 04:22:40
问题 I have the following query and code running and I want the two columns returned on a KeyValuePair. I see the total row returned is right but all the keyvaluepairs are nul ! string query = @"Select id,name from persons"; var persons = context.Database.SqlQuery<KeyValuePair<string,string>>(query); I have seen an answer saying that I have to create a class to get the result; but my question is can't I get the result on KeyValuePair ? Or I must have a class defined with properties matched ? 回答1:

Saving Entity causes duplicate insert into lookup data

烈酒焚心 提交于 2019-12-24 03:32:16
问题 I am using EF 4.1 "code first" to create my db and objects. Given: public class Order { public int Id { get; set; } public string Name { get; set; } public virtual OrderType OrderType { get; set; } } public class OrderType { public int Id { get; set; } public string Name { get; set; } } An order has one ordertype. An order type is just a look up table. The values dont change. Using Fluent API: //Order ToTable("order"); HasKey(key => key.Id); Property(item => item.Id).HasColumnName("order_id")