【问题标题】:Entity Framework 4.0 model doesn't get all dataEntity Framework 4.0 模型无法获取所有数据
【发布时间】:2017-11-11 15:49:30
【问题描述】:

我正在尝试将模型发送到 wcf 服务。 首先我有一个序列化问题,但我通过设置解决了它

ContextOptions.ProxyCreationEnabled = false;

推荐人DataContractSerializer Error using Entity Framework 4.0 with WCF 4.0 但现在模型属性税和产品为空

public ClientWindowViewModel()
    {
        Ip = ServerWindowViewModel.LocalIP;
        db = new STOREDBEntities();
        db.Configuration.ProxyCreationEnabled = false;
        products = db.Products;//.Where(p => p.IsSynced == false)
    }

产品型号

public partial class Product
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
        public Product()
        {
            this.Categories = new HashSet<Category>();
        }

        public int Id { get; set; }
        public string ProductName { get; set; }
        public byte[] Image { get; set; }
        public bool IsDeleted { get; set; }
        public bool IsSynced { get; set; }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<Category> Categories { get; set; }
        public virtual Tax Tax { get; set; }
    }

发送到 WCF 服务器

channel.Update(checkedProducts);

【问题讨论】:

    标签: c# entity-framework wcf


    【解决方案1】:

    如果我错了,请纠正我,您想通过 WCF 合同发送 Product 类,并且在发送后您只得到空值和默认值?

    如果没有在 Product 类中设置适当的注释,如 [DataContract]、[DataMember],则无法通过 WCF 发送对象。

    在类上方设置 [DataContract],在每个属性上方设置 [DataMember]。没有这个,消息将无法正确序列化。

    【讨论】:

    • 是的。我找到了答案,见上面:)
    猜你喜欢
    • 2011-07-07
    • 1970-01-01
    • 2014-03-22
    • 2011-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多