简体   繁体   English

使用实体框架将json对象添加为数据库中的BLOB

[英]Add json objects as BLOB in database with entity framework

I am new with the entity framework. 我是实体框架的新手。 I have a dashboard with widgets and this is my table in Microsoft SQL server. 我有一个带有小部件的仪表板,这是我在Microsoft SQL Server中的表。 表

The reason I have widgets as a blob and not as a seperated entity is because I am not gonna query on the widgets table. 我将小部件作为斑点而不是单独的实体的原因是因为我不会在小部件表上进行查询。 Only data like SELECT * FROM Dashboard WHERE dashboardid =x SELECT * FROM Dashboard WHERE dashboardid =x

This is my DashboardDAL class: 这是我的DashboardDAL类:

public class DashboardDAL
{
    public Dashboard GetDashboardPerUser()
    {
        throw new NotImplementedException();
    }

    public string AddWidget()
    {
        throw new NotImplementedException();
    }
}

I want to add a widget with the entity framework. 我想在实体框架中添加一个小部件。 A Json object of a widget looks like this: 小部件的Json对象如下所示:

{name:"Weather", dashboardid:"2", userID:"4", "x":1,"y":0,"width":3,"height":1}

How can I add a widget object and save it as a BLOB in the database? 如何添加小部件对象并将其另存为BLOB在数据库中?

Kind regards 亲切的问候

JSON is a string. JSON是一个字符串。 Use a string property on an entity to store it with EF. 在实体上使用字符串属性可将其与EF一起存储。 This will map to a NVARCHAR(MAX) column in SQL Server, which is the correct type for storing JSON in SQL Server. 这将映射到SQL Server中的NVARCHAR(MAX)列,这是在SQL Server中存储JSON的正确类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM