poco

Fetching Strategy example in repository pattern with pure POCO Entity framework

北城以北 提交于 2020-01-13 06:52:29
问题 I'm trying to roll out a strategy pattern with entity framework and the repository pattern using a simple example such as User and Post in which a user has many posts. From this answer here, I have the following domain: public interface IUser { public Guid UserId { get; set; } public string UserName { get; set; } public IEnumerable<Post> Posts { get; set; } } Add interfaces to support the roles in which you will use the user. public interface IAddPostsToUser : IUser { public void AddPost(Post

EF4 can’t add an object to the context even though I’m convinced it is not attached

那年仲夏 提交于 2020-01-06 19:51:19
问题 I can’t add an object to the ObjectContext even though I’m convinced it is not attached and it is not associated with a different context I am using EF 4 with POCO objects. If I try _currentContext.ObjectStateManager.GetObjectStateEntry(entityIn) Then I get the error The ObjectStateManager does not contain an ObjectStateEntry with a reference to an object of type 'System.Data.Entity.DynamicProxies.OrderItem_7D361CB49D75AA90681B4BA3F924139ECB0FC1426E38E90C7B884A4E9CD777DF'. Fair enough it’s

代码优先与模型/数据库优先[关闭]

空扰寡人 提交于 2020-01-06 15:41:12
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 使用实体框架4.1代码优先于模型/数据库优先使用EDMX图表有什么优缺点? 我正在尝试完全理解使用EF 4.1构建数据访问层的所有方法。 我正在使用Repository模式和 IoC 。 我知道我可以使用代码优先方法:手动定义我的实体和上下文,并使用 ModelBuilder 来微调模式。 我还可以创建 EDMX 图并选择使用T4模板生成相同 POCO 类的代码生成步骤。 在这两种情况下,我最终都得到了与 ORM 无关的 POCO 对象和源自 DbContext 上下文。 数据库优先似乎最吸引人,因为我可以在企业管理器中设计数据库,快速同步模型并使用设计器对其进行微调。 那么这两种方法有什么区别? 是仅仅关于VS2010与企业管理器的偏好? #1楼 代码优先似乎是后起之秀。 我快速浏览了Ruby on Rails,它们的标准是代码优先,具有数据库迁移。 如果您正在构建MVC3应用程序,我相信Code首先具有以下优势: 简单的属性修饰 - 您可以使用验证,要求等属性来装饰字段,这对于EF建模来说非常尴尬 没有奇怪的建模错误 - EF建模通常会出现奇怪的错误,例如当您尝试重命名关联属性时,它需要匹配底层的元数据 - 非常不灵活。 合并并不尴尬 - 当使用像mercurial这样的代码版本控制工具时,合并

Persisting disconnected POCO entities

痞子三分冷 提交于 2020-01-05 12:28:13
问题 I'm working with disconnected POCO objects. When I persist a single object, it works fine! The problem starts when I want to persist related objects. For example: Retrieving object from Data layer: using (MyContext ctx = new MyContext ()) { return ctx.Users.First(); } This object goes back to Business layer and there, I add some child records, see below (just to ilustrate): objectUser.Permissions.Add(new Permission()); objectUser.Permissions.Add(new Permission()); Permissions is a navigation

Adding code to Entity Framework 4 generated POCOs

江枫思渺然 提交于 2020-01-05 07:07:28
问题 Starting from an EF 4 entity diagram and using T4 templates one can create POCO classes that can be used inside the Domain Model. The generated code looks like this: public partial class Product { public virtual int Id { get; set; } public virtual string Name { get; set; } //and so on } Is there any elegant approach to add my own code for implementing the properties? for example, the Name setter I would like to be implemented by lowering all the characters. I would like that my code resist to

Windows Phone 8 MVVM Database First (like EF)

核能气质少年 提交于 2020-01-02 23:44:49
问题 Is there any framework for Windows Phone 8 which is similar in use to Entity Framework for generating POCOS from an existing database? 回答1: LINQ to SQL: A SQL Server Compact database combined with my SQL Server Compact Toolbox for the code generation. If you have VS Express, you can use the standalone edition, download from http://sqlcetoolbox.codeplex.com 来源: https://stackoverflow.com/questions/18482525/windows-phone-8-mvvm-database-first-like-ef

Convert POCO object to Proxy object in EntityFramework

此生再无相见时 提交于 2020-01-02 06:43:12
问题 I have a MVC3 Project and I have run into a problem. I have a Create controller which takes as a parameter one of my POCO objects. I add this object to the database like this: entity = dbSet.Add(entity); After this method returns, I would like to use the lazy loading features of the object. Unfortunately the object is not a Proxy object generated by the EntityFramework...Is there a way to somehow solve this? Thank You, AFrieze 回答1: The entity must be already proxied when you pass it to Add

WCF REST service won't return children of Entities

China☆狼群 提交于 2020-01-02 06:19:34
问题 I have written a WCF service with the REST template that has the defaultOutgoingResponseFormat set to Json. Under that, I have built a simple entity model using Entity Framework and ObjectContext, in order to pass around custom POCO entities. If I pass a single entity, the system works as expected. If I add children to the entity, the REST response is blank. In the debugger, the entity is populated correctly, but the service itself returns nothing at all. So, for instance, I have a Trip.Get()

Include derived property into a linq to entity query

拜拜、爱过 提交于 2020-01-02 05:56:19
问题 Here is a simple project based on a Poco class named Task : class Program { static void Main(string[] args) { using (MyDbContext ctx = new MyDbContext()) { // first query DateTime compareDate = DateTime.Now + TimeSpan.FromDays(3); var res = ctx.Tasks.Where(t => t.LastUpdate < compareDate).ToList(); // second query res = ctx.Tasks.Where(t => t.ShouldUpdate).ToList(); } } } public class MyDbContext : DbContext { public DbSet<Task> Tasks { get; set; } } public class Task { public int ID { get;

Entity Framework classes vs. POCO

荒凉一梦 提交于 2020-01-01 09:46:27
问题 I have a general difference of opinion on an architectural design and even though stackoverflow should not be used to ask for opinions I would like to ask for pros and cons of both approaches that I will describe below: Details: - C# application - SQL Server database - Using Entity Framework - And we need to decide what objects we are going to use to store our information and use all throughout the application Scenario 1: We will use the Entity Framework entities to pass all around through