【问题标题】:Receive bytea with asp .net api使用 asp .net api 接收 bytea
【发布时间】:2020-10-15 07:36:01
【问题描述】:

首先,对于可能出现的英文错误,我们深表歉意

我使用实体框架在我的 postgresql 数据库中创建了一个表。

在创建部分的 edmx 中,我作为 bytea 传递,但在映射中我使用二进制(必须使用原始类型)。

<EntityType Name="styleexample">
      <Key>
        <PropertyRef Name="id" />
      </Key>
      <Property Name="id" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
      <Property Name="example" Type="String" MaxLength="40" />
      <Property Name="example1" Type="Binary" />
      <Property Name="example2" Type="DateTime" />
</EntityType>

<EntityType Name="styleexample">
      <Key>
        <PropertyRef Name="id" />
      </Key>
      <Property Name="id" Type="int4" StoreGeneratedPattern="Identity" Nullable="false" />
      <Property Name="example" Type="varchar" MaxLength="40" />
      <Property Name="example1" Type="bytea" />
      <Property Name="example2" Type="timestamp" />
</EntityType>

表格是用正确的类型创建的

在实体中,我将该列引用为字节 []

在列中我插入了一个png图像的base64字符串,但是在服务中我返回的值与我插入的不同

我的回复也是byte[]

它有效。但是,它返回不正确的值。是否有其他方法来执行此过程?

【问题讨论】:

    标签: entity-framework .net-4.0 edmx postgresql-12 bytea


    【解决方案1】:

    我通过添加服务解决了这个问题

    var example1 = new StreamReader(new MemoryStream(estilo.example1));
    var example1Stream = example1 .ReadToEnd();
    

    【讨论】:

      猜你喜欢
      • 2017-12-17
      • 2013-02-05
      • 1970-01-01
      • 2015-04-16
      • 2013-10-06
      • 1970-01-01
      • 1970-01-01
      • 2020-03-25
      • 1970-01-01
      相关资源
      最近更新 更多