entity-framework-4

Is it possible to execute an efficient multiple row DELETE or UPDATE using EF4?

不羁的心 提交于 2019-12-06 10:26:20
问题 I'm a developer still learning the intricacies of EF4. I am well aware of how to pull down a list of objects and iterate through deleting them in a loop but I can't bring myself to write code that will execute n statements (and database round-trips) for n records when doing a mass update or delete. A classic case for this is deleting child records prior to deleting a related parent record to maintain referential integrity... (yes, I employ soft deletes by default but humor me) In a stored

Can EF4 generate POCO for me, or do I have to write them myself?

断了今生、忘了曾经 提交于 2019-12-06 09:57:14
问题 I've been playing about with the Entity 4 framework lately and it's pretty nifty. I've setup a class called Customer.cs with some properties like Name, Address etc. I also have a class called StoreEntities.cs which binds these back to the database through DbSet. It works fine and I can pull all my customers from the database. The problem is every tutorial I come across on the internet generates their classes by hand. What I mean is, they all say something like "Now I'm going to make a new

How do I SaveChanges on a joined view of 2 or more tables using Entity Framework?

半腔热情 提交于 2019-12-06 09:47:16
In order to get practice with Entity Framework, I am creating a C# WinForms project, and I used the answer to the question in this link to join and display tables in a datagridview: Two entities in one dataGridView I have searched for a clean way to save (to the SQL Server database) the changes made in the datagridview. Is there a good, fast, short, clean way? I have seen some ugly attempts, and even if they work, I am turned off by their ugliness. With one table only (no joins), calling .SaveChanges works fine. Here is the class set up to hold the joined fields: public class CustAndOrders { /

How to append a where clause to an Entity Framework ObjectSet

懵懂的女人 提交于 2019-12-06 09:46:41
I would like to append a set of conditional where clauses onto the end of an ObjectSet. However, the clauses do not get executed and instead the original query is run, for example: using (Entities context = new Entities()){ var q = context.AuditLogs; q.Where(o => o.WebsiteId == 1); } The where clause is not executed and the full result set is returned I could instead use IQueryAble as in: var q = context.AuditLogs.AsQueryable(); q = q.Where(o => o.WebsiteId == 1); However this loses me the power of being able to use .Include to eager load my related entities. No, it won't. at any point before

Entity Framework 4: Many to Many relationship IQueryable instead of ICollection

自闭症网瘾萝莉.ら 提交于 2019-12-06 09:29:43
Good morning everyone, I am trying to tackle a problem I run into with EF code first. My schema is the following public class Article : IUrlNode { [Key] public Guid ArticleID { get; set; } public string Title { get; set; } public DateTime DateCreated { get; set; } public DateTime DateUpdated { get; set; } public string Summary { get; set; } [System.ComponentModel.DataAnnotations.InverseProperty("CategoryArticles")] public virtual IQueryable<Category> ArticleCategories { get; set; } public string FriendlyUrl { get; set; } } [RouteChild("CategoryArticles")] public class Category : ContentNode {

Dynamic Data - Make Friendly Column Names?

最后都变了- 提交于 2019-12-06 09:27:47
问题 I've created a Dynamic Data project with an Entity Framework model. It works nicely. But, right now it shows all my database tables with the db column names - which aren't always the most friendly (e.g. address_line_1). How can I got about giving these more friendly column titles that will display to the end user? 回答1: You should use Metadata classes to add additional annotations: [MetadataType(typeof(MovieMetaData))] public partial class Movie { } public class MovieMetaData { [Required]

How to add or remove a many-to-many relationship in Entity Framework?

别等时光非礼了梦想. 提交于 2019-12-06 09:02:41
There's a many-to-many UserFeed table that stands between User and Feed and denotes a twitter-like follow relationship. It only has two fields, which form a composite key: UserID and FeedID . I need to write a method that will subscribe or unsubscribe a user from a feed based on a boolean flag. public void SetSubscriptionFlag (int userId, int storeId, bool subscribe) { } I'm new to Entity Framework so I'm trying to find and follow an "EF-ish" way to accomplish this. My initial thoughts are: Instead of working with the middle UserFeed class, I should create a many-to-many Subscriptions property

Changing entity name/poco class name from table name while creating model from the database

血红的双手。 提交于 2019-12-06 08:59:43
I want to create a entity model from the existing database but all the table names contain "_"/underscore in the database so while creating poco classes i want remove underscore from name of the entities/poco classes. Is there a way to change the naming convention while the entities are created in the entity framework during the creation of model from database Thanks, Amit You have two options, There is a little bit of a learning curve but it involves using T4 templates to do the code generation yourself. Basically you would just strip out the _ in the conceptual model. guide to customizing

Entity Framework 4 SaveChanges not working and not throwing any error?

◇◆丶佛笑我妖孽 提交于 2019-12-06 08:59:38
I am trying to use my generic repository with a "unit of work" pattern. Here is my work details public class GenericRepository:IRepository { private readonly string _connectionStringName; private ObjectContext _objectContext; private readonly PluralizationService _pluralizer = PluralizationService.CreateService(CultureInfo.GetCultureInfo("en")); public GenericRepository() { this._objectContext = ContextManager.CurrentFor(); } public void Add<TEntity>(TEntity entity) where TEntity : class { ((DataEntities.MyTestDBEntities)_objectContext).Countries.AddObject(new Country() { CountryName="UGANDA"}

EF 4.0 generics based inheritance

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 08:39:51
问题 I have a class like this public abstract class BaseType<T> { public string Name {}; public T TypedValue { get { return GetTypedValue(PersistedValue); } }; public string PersistedValue {} public abstract T GetTypedValue(PersistedValue); } then many derived classes like public class IntegerType:BaseType<int> { ... } is it possible to map this hierarchy using EF 4.0 using Table per inheritance scheme ? Currently the generated code creates has an error because it generates a property like public