我正在创建一个Web API端点,它将作为一种服务来检索我们的应用程序配置,执行日志记录等.我遇到的问题是能够在控制台应用程序中反序列化Json.
建立
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime DateOfBirth { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
Web API
[HttpGet]
[Route("Person")]
public IHttpActionResult GetPerson()
{
Person person = new Person
{
FirstName = "Steve",
LastName = "Rogers",
DateOfBirth = new DateTime(1920, 7, 4)
};
return Ok(JsonConvert.SerializeObject(person));
}
Run Code Online (Sandbox Code Playgroud)
控制台应用
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost");
var response = client.GetAsync("api/Person").Result;
var data = response.Content.ReadAsStringAsync().Result;
var …Run Code Online (Sandbox Code Playgroud) 我试图从EntityFramework中的显式加载过滤结果.
当我不应用任何过滤器但是在应用过滤器后它不加载结果时,显式加载有效.
类
public partial class Student
{
public int StudentId { get; set; }
public int CourseId { get; set; }
public string Name { get; set; }
public string Status { get; set; }
public virtual ICollection<Grade> Grades { get; set; }
}
public partial class Grade
{
public int GradeId { get; set; }
public string Value { get; set; }
public string Status { get; set; }
public virtual ICollection<Student> Students { get; set; }
} …Run Code Online (Sandbox Code Playgroud) 为了在 WPF 中实现数据绑定,根据 MS 的说法,“类需要提供适当的属性更改通知”。[参考这里]
AFAIK,设置的一部分意味着采取以下步骤,如果尚未在类中设置(参考MSDN 上的这篇文章):
set可以更改属性并调用方法来引发事件。...
// Create the OnPropertyChanged method to raise the event
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
Run Code Online (Sandbox Code Playgroud)
如果我已经有许多现有的类不采取任何这些步骤,那么更改这些类的最佳方法是什么,以便它们仅在满足这些标准所需的范围内进行更改?
我试图实现一个通用存储库,现在我有这个:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.Entity.Core.Objects;
using Web_API.Models;
namespace Web_API.DAL
{
class GenericRepository<T> : IRepository<T> where T : class
{
private ApplicationDbContext entities = null;
IObjectSet<T> _objectSet;
public GenericRepository(ApplicationDbContext _entities)
{
entities = _entities;
_objectSet = entities.CreateObjectSet<T>();
}
...
Run Code Online (Sandbox Code Playgroud)
我在调用此方法时遇到问题:
entities.CreateObjectSet<T>();
应该没问题,但是我收到此错误:
我已经将 System.Data.Entity 添加到我的项目中,此时我不知道还能做什么。我正在关注本教程http://www.codeproject.com/Articles/770156/Understanding-Repository-and-Unit-of-Work-Pattern。有谁知道如何解决这个问题?
c# asp.net entity-framework repository-pattern asp.net-web-api
我需要修改下面提到的方法来返回字符串列表.它将以contactid作为输入,并应返回问卷清单
public string GetFatcaQuestionnaire(int contactId, string questionnaireType)
{
using (var context = new dbDealingContainer())
{
if (context.Connection.State == ConnectionState.Closed)
context.Connection.Open();
var fatcaQuestionaires = context.FatcaQuestionaires.FirstOrDefault(p => p.ContactID == contactId && p.QuestionnaireType == questionnaireType);
return fatcaQuestionaires != null ? fatcaQuestionaires.Questionaire : null;
}
}
Run Code Online (Sandbox Code Playgroud)
新提出的方法
public List<string> GetFatcaQuestionnaire(int contactId)
{
using (var context = new dbDealingContainer())
{
if (context.Connection.State == ConnectionState.Closed)
context.Connection.Open();
var fatcaQuestionaires = context.FatcaQuestionaires.Select(p => p.ContactID == contactId).ToList();
return fatcaQuestionaires.ToList();
//return fatcaQuestionaires.ToList() != null ? fatcaQuestionaires : null;
}
} …Run Code Online (Sandbox Code Playgroud) 如何生成参数未知的方法?
我Microsoft.CSharp.dll用来编译c#脚本:
CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerParameters compilerParams = new CompilerParameters { GenerateExecutable = false, GenerateInMemory = true };
string scriptCode = GetFullCode(); //here i add usings and so on
var results = provider.CompileAssemblyFromSource(compilerParams, scriptCode);
Run Code Online (Sandbox Code Playgroud)
所以,我需要添加一些一些功能,但这种功能可与任意数量的参数和类型(列表DateTime,int,double等).
函数应该像这样调用:
function(String,String,DateTime,int,...);
Run Code Online (Sandbox Code Playgroud)
要么
function(DateTime,int,String,..);
Run Code Online (Sandbox Code Playgroud)
等等.
用户可以在代码中使用此功能.
如何生成这个功能?例如,我告诉我现在如何生成代码:
// GetFullCode:
StringBuilder sb = new StringBuilder();
foreach (DictionaryEntry de in Assembles)
{
foreach (var us in de.Value.ToString().Split(new char[] { ';' }))
{
if (!string.IsNullOrWhiteSpace(us))
sb.AppendLine("using " + …Run Code Online (Sandbox Code Playgroud) 我已经从源代码构建了 vscode,因为我想为它添加一个新功能。不幸的是,我似乎无法安装扩展。我使用 gulp 任务构建了一个 .deb 包,并安装了它
它缺少“安装扩展”菜单和其他一些菜单。
我现在运行的版本:代码 - OSS - 版本 1.2.1 - 提交 fe7f407b95b7f78405846188259504b34ef72761
还有什么我必须构建/安装才能从编辑器内部安装扩展吗?
namespace BusinessLayer
{
public class StudentBusinessLayer
{
public List<Student> getStudents(string storedProcedure)
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString))
{
List<Student> students = new List<Student>();
SqlCommand comm = new SqlCommand(storedProcedure, conn);
comm.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlDataReader rdr = comm.ExecuteReader();
while (rdr.Read())
{
Student s = new Student();
s.id = Convert.ToInt32(rdr["id"]);
s.Name = rdr["Name"].ToString();
s.TotalMarks = Convert.ToInt32(rdr["TotalMarks"]);
students.Add(s);
}
return students;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)