entity-framework-4

EF4 - Context.Entry isn't available to change an Entity State

让人想犯罪 __ 提交于 2019-12-06 07:21:27
问题 I use an EDMX schema as my context. On a previous project where I didn't use a schema, I could change the entity state like this: public void SaveProduct(Product product) { if (product.ProductID == 0) context.Products.Add(product); else context.Entry(product).State = EntityState.Modified; context.SaveChanges(); } But in this project, I don't see .Entry in my intellisense (and it won't suggest a namespace reference if I just type it in). I tried to modify an entity ans save it. It worked

Performance of stored procedures & Entity Framework

走远了吗. 提交于 2019-12-06 07:02:08
问题 Are there any obvious reasons why calling a stored procedure via my entity model would result in far slower performance than calling it direcly? Firstly, I don't expect the SP to run at exactly the same speed and I know that there are various things that EF has to do that wouldn't be called when accessing the SP directly. That aside, I have a query that returns three columns of strings. It runs pretty much instantly when I execute it via Enterprise Manager. If I run it via EF then it takes

Entity Framework 4 (CTP 5) unwisely queries in comparison with LINQ-to-SQL

倖福魔咒の 提交于 2019-12-06 06:35:07
问题 I have an issue about Entity Framework 4 CTP 5, which I realize LINQ to SQL handle it better than this, but I insist on using EF 4 because of its Code-First feature. So here is my problem: Imagine products with its Tags (or whatever with one to many relation). And tblTags will be changing by deleting some and inserting some tags at a time by user (and user might change them completely different). So in my opinion we can simply delete all old tags and insert new ones (simplest thing to do),

If you create a DomainService, exposing an entity, can you access aggregate entities?

折月煮酒 提交于 2019-12-06 06:28:57
问题 Say you create an RIA DomainService and you include a Person (shown below) entity in it, can you access aggregate entities on that object? For instance, if I have entities like so (keep in mind that this is a naive representation, they are modeled via the EF4 designer): public class Person { string FirstName { get; set; } PhoneNumber { get; set; } } public class PhoneNumber { public string AreaCode { get; set; } public string Trunk { get; set; } public string Number { get; set; } } If I

How To Count Associated Entities using Where In Entity Framework

放肆的年华 提交于 2019-12-06 06:09:34
I have this: var queryResult = (from post in posts select new { post, post.Author, post.Tags, post.Categories, Count = post.Comments.Count() }).ToList(); But I need something like this: var queryResult = (from post in posts select new { post, post.Author, post.Tags, post.Categories, Count = post.Comments.Where(x=>x.IsPublic).Count() }).ToList(); But post.Comments is a ICollection How about using Enumerable.Cast<T>() like this ? var queryResult = (from post in posts select new { post, post.Author, post.Tags, post.Categories, Count = post.Comments.Cast<Comment>() .Where(x=>x.IsPublic).Count() })

When should entity framework be used?

别等时光非礼了梦想. 提交于 2019-12-06 06:03:11
I'm new to Entity Framework and, of course, I have found few questions on SOF with regards to target use-cases. Let me give you some information. I'm not dealing with different database vendors or different databases; one, and only one, SQL Server 2008 and the database has less than 30 tables. Do I really need to redo things and go with Entity Framework? EDIT: Thanks to James for fixing my question. So I'm assuming using EF adds up overhead and does some work in background which I won't know. This is MS working style so I guess my next questions are: Does it affect performance as well? Does it

How to use Entity Framework 4.0 with Xml or in-memory Storage (non-SQL)

偶尔善良 提交于 2019-12-06 05:55:13
How do I specify Xml or just in-memory storge for Entity Framework models? The connection string requires a provider (usually a SQL provider string). But it won't let me omit the provider. I realize I could completely throw away the designer generated objects and go pure POCO, but then I'd have to implement my own serialization layer (could do that, but it's overkill for the tiny project I'm working on). Is there built-in support in EF 4.0 for this that I'm missing or do I just need to go the pure POCO route and discard the designer experience entirely :( Shiraz Bhaiji If you want to store

Is my understanding of POCO's + Entity Framework v4, correct?

我们两清 提交于 2019-12-06 05:44:43
can someone please confirm/correct me, with my understanding of using POCO's with the Entity Framework v4? If I'm going to want to use POCO's with my EF4 context, do I still need to place/create ENTITIES on the designer/.edmx ? Isn't the idea of using POCO's so I don't need to use those 'heavy' entities? or do i still need those entities, it's just that somewhere else I actually move the data out of the entities and into my POCO's .. which is what gets used by any consuming code? If you want to use POCO you have three choices: First choice is to create EDMX model. In EDMX you will turn off

Entity Framework - IQueryable to DataTable

谁都会走 提交于 2019-12-06 05:37:08
问题 I'm trying to convert an IQueryable object to a DataTable . Here's an example of a query that I would like to convert to a DataTable : var query = DbContext.SomeObjectSet.Select(x => new { PropertyName1 = x.ColumnName1, PropertyName2 = x.ColumnName2 }); Please note the anonymous object that is created in the Select method and the names of the properties: new { PropertyName1 = x.ColumnName1, PropertyName2 = x.ColumnName2 } After Googling this issue, I came across the following code that

Can we use EF migrations with MySql

不羁的心 提交于 2019-12-06 05:16:21
问题 Is there a way to use EntityFramework 4.3 beta with migrations with MySql database? Can we use migrations with MySql Database? Is it possible to use incremental database development with EF code first without me touching the database 回答1: Theoretically yes. Practically you first need to get (or create yourselves) class derived from System.Data.Entity.Migrations.Sql.MigrationSqlGenerator which will be responsible for generating SQL for MySQL. Here is more about customizing (or rewriting) SQL