有手就行?sql server 使用 entityframwork 从数据库提取一行数据并输出为json文件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Data;
using Newtonsoft.Json;
using System.IO;


Class Program 
{
//初始化实体模型
public static CbjGameProjectXBDB1_3Entities dbContext   = new CbjGameProjectXBDB1_3Entities ();


//转化为json的主要方法
public static string GetJson(object o)
{

  JavaScriptSerializer json = new JavaScriptSerializer();

            return json.Serialize(myInfo);


}

//写一个IO输出方法
public static void  Output(string str,str Path)
{

            StreamWriter sw = new StreamWriter(Path, false);

            sw.WriteLine(str);

            sw.Close();


}


static void Main(string[] args)
{
	 

            var context = dbContext.BuildingInfo.Where(p => p.ID > 0);

            string Path = "F:/System_IO文件/Test.json";

            string json = GetJson(context);

            Output(json, Path);

            Console.Write(json);

            Console.Write("\n");

            Console.ReadLine();

            

}

在这里插入图片描述

发布了251 篇原创文章 · 获赞 42 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/qq_38992403/article/details/103955634