Tag: poco

AutoMapper,如何在映射对象之间保持引用?

我正在使用AutoMapper将UI模型转换为POCO,后来我使用DataContractSerializer将其序列化为XML,以便保留它们之间的引用。 问题是,在映射时, 这些实体之间的引用会丢失 。 UI类相互引用,但映射过程为每个引用创建新实例,因此原始关系被破坏:( 让我解释: 我有2个Person类型的实体 Person { List OwnedHouses } 而这2个对象 拥有的约翰 House1 谁也拥有谁 House1 当AutoMapper正确映射每个Person时,但它也将House1映射为两个不同的实例!! 所以我有两份House1。 John拥有他的House1(#1)并且Will拥有他的House1(#2)。 他们不再联系了。 有没有办法保持最初存在的关系? 谢谢。 编辑:其实我的拥有是这样的: 文档包含ChildDocuments列表。 每个ChildDocument都有一个Designables列表(Rectangles,Lines,Ellipses …)和一个名为ChildDocumentAdapter的特殊设计,它包含自己的ANOOTHER ChildDocument。 这是麻烦,它可以引用另一个ChildDocument。

在c#中序列化和存储对象的最简单方法?

我正在寻找一个简单的解决方案来序列化和存储包含配置,应用程序状态和数据的对象。 它是一个简单的应用程序,它不是很多数据。 速度没问题。 我希望它在进行中。 我希望它在texteditor中比xml更容易编辑。 我无法找到.net的任何文件数据库,可以在进程中处理它。 只是序列化为xml我不确定我想要做什么,因为它的… xml。 序列化为JSON似乎非常具有javascript,我不会在javascript中使用这些数据。 我认为有很好的方法可以做到这一点,但我仍然倾向于使用JSON,尽管它的javascript inflenation。

如何编写自定义POCO串行器/解串器?

我想为FIX消息编写一个自定义的.NET序列化器/解串器(它不像XML)。 基本上,消息编码为=;=;… 所以样本可能是: 51=2;20=hello;31=2 我想使用我的FIX Serializer类,类似于我使用XMLSerializer类来序列化/反序列化消息的方式。 我想我会写一个FIX消息类,如: [Serializable] public class FixMessage { [FIXValuePair(51)] public double Price { get; set; } [FIXValuePair(20)] public string SomethingElse { get; set; } } 关于如何编写这样的Serializer / Deserializer的任何指针?

entity frameworkIQueryable与poco生成

我已经创建了一个T4模板,它为每个属性生成标准的Entities类和Interfaces,这样我就可以制作只包含我想要的数据的自定义poco对象。 我还创建了一个复制函数,它可以在实现所述实体接口的任何对象之间进行转换 生成的代码如下所示 //—————————————————————————— // // This code was generated from a template. // // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // //—————————————————————————— namespace DomainModel { using System; using System.Collections.Generic; using System.Linq; public interface IRole […]

代码首先导致所需的关系是可选的?

public class Client { public Int32 ClientID { get; set; } public virtual ICollection InquiryManufacturers { get; set; } public virtual ICollection Products { get; set; } public virtual ICollection InquiryRetailers { get; set; } } public class Product { public Int32 ProductID { get; set; } public Int32 ClientID { get; set; } public […]

C#模型的自定义设置器

我不知道如何为C#数据模型制作自定义setter。 场景非常简单,我希望我的密码能够使用SHA256function自动加密。 SHA256function非常好(我以前用过很多项目)。 我尝试了几件事,但是当我运行update-database ,似乎它正在递归地执行某些操作并且我的Visual Studio挂起(不发送错误)。 请帮助我了解如何在模型中默认加密密码。 用我已经尝试过的代码 public class Administrator { public int ID { get; set; } [Required] public string Username { get; set; } [Required] public string Password { get { return this.Password; } set { // All this code is crashing Visual Studio // value = Infrastructure.Encryption.SHA256(value); // Password = Infrastructure.Encryption.SHA256(value); […]

实体类型不是当前上下文的模型的一部分

大段引用 我现在已经解决了这个问题几天了。 我正在尝试使用Visual Studio 2010 MVC2 EF 6.0创建数据库连接。 我可以使用服务器资源管理器连接到数据库。 这是我到目前为止所做的: 创建了一个Model:ModelEntities.edmx(连接到SQL Server DB) 2.为我正在尝试访问的表创建了一个Model:Table.cs(包含所有公共成员) public class Quickfix { public int FIX_ID { get; set; } public string NAME { get; set; } public string TYPE { get; set; } public string DESCRIPTION { get; set; } } 创建了一个DAL文件夹并将其上下文添加到其中:(ModelEntitesContext.cs) 使用ServiceDesk_Solution.Models; namespace ServiceDesk_Solution.DAL { public class ModelEntitiesContext […]

POCO和多个ViewModel指向同一个POCO?

怎么会处理这样的情况呢? 让多个ViewModel具有对同一POCO对象的引用。 ViewModel A更新POCO …现在ViewModel B需要以某种方式了解这一点?

如何克隆POCO实体并添加到上下文

我正在使用EF4,我已经使用我的数据库结构中的代理创建了POCO对象。 我有一个POCO(对象),它与其他实体有很多关系。 我使用DataContractSerializer和BinaryFormatter创建了对象的深层副本,并将其称为clonedObject。 用于克隆的函数是: public T CloneProxy(T source) { var dcs = new System.Runtime.Serialization .DataContractSerializer(typeof(T)); string filePath = “Initiative.txt”; using (FileStream file = new FileStream(filePath, FileMode.Create)) { (new BinaryFormatter()).Serialize(file, source); } context.CreateProxyTypes(new Type[] { typeof(Initiative) }); using (FileStream file = new FileStream(filePath, FileMode.Open)) { return (T)(new BinaryFormatter()).Deserialize(file); } } 现在我有了clonedObject,如何将其添加到上下文中? 如何将其添加到数据库? 我的目标(只是给你一个关于POCO倡议的想法): Initiative { InitI […]

使用RestSharp客户端反序列化嵌套的JSON响应

我想使用REST Api并反序列化嵌套的JSON响应。 为此,我尝试创建一些代表JSON Response [1]的POCO类。 响应如下: { “success”: true, “message”: “OK”, “types”: [ { “name”: “A5EF3-ASR”, “title”: “ITIL Foundation Plus Cloud Introduction”, “classroomDeliveryMethod”: “Self-paced Virtual Class”, “descriptions”: { “EN”: { “description”: “some Text null”, “overview”: null, “abstract”: “Some other text”, “prerequisits”: null, “objective”: null, “topic”: null } }, “lastModified”: “2014-10-08T08:37:43Z”, “created”: “2014-04-28T11:23:12Z” }, { “name”: […]