本文介绍了如何在C#实体框架模型中使用Json数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
model.cs
[Column(TypeName = "json")]
public string application_role { get; set; }
其MySQL,特定列的数据类型为 json
,以及如何将其添加到模型类中.我尝试使用DataAnnotations,但收到错误消息
Its MySQL, data type of particular column is json
, and how to add it in a model class. I tried with DataAnnotations but getting error as
The specified type member 'application_role' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
Linq查询以获取数据
Linq Query to get data
context.sc_employee_details
.Where(e => e.user_name.Equals(userName))
.Select(o => o.application_role).SingleOrDefault();
推荐答案
可能有点晚,但是MySQL上的EF支持JSON格式,这是公告.基本上,您必须定义一个像这样的属性:
It might be a bit late, but EF on MySQL supports JSON format, here is announcement.Basically, you have to define an attribute like this one:
public JsonObject<string[]> Tags { get; set; } // Json storage
希望有帮助!
这篇关于如何在C#实体框架模型中使用Json数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!