我想要更新他的名字是pejman的人的家庭.这是我的对象类:
public class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set;}
public DateTime BirthDate { get; set; }
public bool IsMale { get; set; }
public byte[] Image { get; set; }
public byte[] RowVersion { get; set; }
public virtual Person Parent { get; set; }
public virtual ICollection<PhoneNumber> PhoneNumber { get; set; }
public virtual ICollection<Address> Addresses { get; set; }
public virtual PersonInfo …Run Code Online (Sandbox Code Playgroud) 我用列Table命名tbl_search:id(int), title(nvarchar100), result(ntext)
我想要使用SQL query,像这样:
using (var db = new GoogleEntities())
{
const string selectCmd =
@"Select top 1 title From tbl_search Where title=@title and id=@id ";
var data = db.Database.SqlQuery<tbl_search>(
selectCmd,
new SqlParameter("@title", "wcf"),
new SqlParameter("@id", 1)
).FirstOrDefault();
if (data != null)
{
var serviceMember = data.ToString();
label1.Text = serviceMember == "" ? "" : (serviceMember == "True" ? "On" : "Off");
}
}
Run Code Online (Sandbox Code Playgroud)
但它给了我一个错误:
数据阅读器与指定的"GoogleModel.tbl_search"不兼容.类型为"id"的成员在数据读取器中没有具有相同名称的相应列.
注意:这是我的tbl_search班级:
public partial class …Run Code Online (Sandbox Code Playgroud) 我在asp.net核心创建一个Web Api这个Api的内容:
[Route("api/[controller]")]
public class BlogController : Controller
{
public IContext _context { get; set; }
public BlogController(IContext ctx)
{
_context = ctx;
}
[HttpGet]
[Route("api/Blog/GetAllBlog")]
public List<Blog> GetAllBlog()
{
return _context.Blogs.ToList();
}
}
Run Code Online (Sandbox Code Playgroud)
正如我在ASp.net核心(WebApi模板)中所知,我们不需要任何配置,如注册路由,我们需要在Asp.net Mvc 5.3及更早版本.
因此,当我尝试GetAllBlog通过浏览器或邮递员调用时,通过此URL http://localhost:14742/api/Blog/GetAllBlog,它会让我404 error,问题是什么?
我构建了一个应用程序Asp.net core,我创建了一个.Net core class library单元测试,我想IHostingEnvironment在我的库中使用(用于获取文件的物理路径),所以我将它添加到我的Asp.net核心应用程序服务的startup.cs:
services.AddSingleton<IHostingEnvironment>();
Run Code Online (Sandbox Code Playgroud)
在库中我添加了对我的Asp.net应用程序的引用,并在我的库中的类我写道:
private IHostingEnvironment _env;
public Class1(IHostingEnvironment env)
{
_env = env;
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,它给了我这个错误:
以下构造函数参数没有匹配的fixture日期:IHostingEnvironment env
问题是什么?我该如何使用它.NetCore library?
编辑:我也这样使用:
IServiceCollection services = new ServiceCollection();
services.AddSingleton<IHostingEnvironment>();
IServiceProvider provider = services.BuildServiceProvider();
IHostingEnvironment service = provider.GetService<IHostingEnvironment>();
var p = service.WebRootPath; // give this error: Cannot instantiate implementation type 'Microsoft.AspNetCore.Hosting.IHostingEnvironment' for service type 'Microsoft.AspNetCore.Hosting.IHostingEnvironment'
Run Code Online (Sandbox Code Playgroud)
但它也不起作用.
我知道Asp.Net MVC并且Asp.Net Web API被合并到一个代码中Asp.net Core并且它们从Controller基类继承并且都可以返回实现IActionResult.对于web api来说,它是MVC或Json的视图.
但是当我想创建一个Asp.net Core项目时,它提供了两个模板(Web Application and Web Api ),根据我上面所说的,这些控制器之间没有区别,为什么有两个模板?我有什么不同之处吗?
出于某种原因,我想在插入对象之前获取对象Ef Core Intreceptor,例如在我想要的时候
var newOrder = new Order { CustomerID = 3, EmployeeID = 4, OrderDate = DateTime.Now };
_myContext.Orders.Add(newOrder);
_myContext.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
我尝试newOrder使用ReaderExecuting方法,Interceptor所以我覆盖了这个方法:
public override InterceptionResult<DbDataReader> ReaderExecuting(DbCommand command, CommandEventData eventData, InterceptionResult<DbDataReader> result)
{
return base.ReaderExecuting(command, eventData, result);
}
Run Code Online (Sandbox Code Playgroud)
这个方法被调用了,那么我怎样才能newOrder使用上面的方法呢?
我知道NHibernate我们可以这样做:
public bool OnPreInsert(PreInsertEvent @event)
{
//some other codes
}
Run Code Online (Sandbox Code Playgroud)
我可以通过 获取对象@event.Entity,但是Ef Core 3有什么办法可以这样做吗?
我在我的项目中使用Protobuf并Dotner Core 3.1安装这个包,但是当我编写这些代码行来序列化请求的对象时:
public static byte[] ProtoSerialize<T>(T record) where T : class
{
try
{
using (var stream = new MemoryStream())
{
Serializer.Serialize(stream, record);
return stream.ToArray();
}
}
catch
{
throw;
}
}
Run Code Online (Sandbox Code Playgroud)
Visual studio找不到相关的名称空间并出现找不到的错误Serializer,
当前上下文中不存在名称“Serializer”
我对其进行了测试.Net并安装了有效的相关软件包,但.Net Core出现了错误。有什么关系namespece?问题是什么?
根据这篇文章在Asp.net Core中使用StyleCop,
1)将以下内容添加到project.json文件的dependencies部分:
"StyleCop.Analyzers": {
"version": "1.0.0",
"type": "build"
}
Run Code Online (Sandbox Code Playgroud)
并构建项目.
2)创建stylecop.json并添加你的配置,这是我的stylecop.json内容:
{
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
"settings": {
"documentationRules": {
"documentInterfaces": true,
"documentInternalMembers": false
}
}
}
Run Code Online (Sandbox Code Playgroud)
3)project.json文件中的buildOptions节点下面的以下内容:
"additionalArguments": ["/additionalfile:path/to/stylecop.json" ]
Run Code Online (Sandbox Code Playgroud)
但是我遇到了一些错误:问题是什么?
我读了一篇关于泛型类的培训文章,它有一些这样的代码:
public class ValidationBase {
public virtual bool IsValidName(string name) {
return name.Length > 5;
}
}
public class LogicBase<T> where T : ValidationBase, new() {
private T _Validations = default(T);
public T Validations {
get {
if (_Validations == null) {
_Validations = new T();
}
return _Validations;
}
set { _Validations = value; }
}
}
Run Code Online (Sandbox Code Playgroud)
它说:
如果没有为 T 提供特定类型,则 new 关键字默认创建 DataModelBase 类的实例
我真的不明白我们new()什么时候应该使用关键字?
注意:如果像这样编辑上面的代码:
public class LogicBase<T> where T : ValidationBase
Run Code Online (Sandbox Code Playgroud)
代替
public class …Run Code Online (Sandbox Code Playgroud) 我有一个母版页,在它的头部,我有:
<script src="Script/jquery.min.js"></script>
<link href="Stylesheet/Master.css" rel="stylesheet" />
Run Code Online (Sandbox Code Playgroud)
我有一个webform(名称= Login.aspx),它继承自我的母版页,在Login.aspx中,我有:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<input id="t1" type="password" placeholder="Passwords" class="login-input-class1" runat="server" ClientID="Static" />
<input id="t2" type="text" placeholder="ConfirmPasswords" class="login-input-class1" runat="server" ClientID="Static"/>
<label class="display" id="lblerror">Error</label>
<script>
$(document).ready(function () {
$("#t2").change(function () {
if ($("#t1").val() === $("#t2").val()) {
$("#lblerror").addClass("display");
}
else {
$("#lblerror").removeClass("display");
}
});
});
</script>
</asp:Content>
Run Code Online (Sandbox Code Playgroud)
在Master.css我有:
.display {
display:none;
Run Code Online (Sandbox Code Playgroud)
}
但我的脚本不起作用,问题是什么?
asp.net-core ×4
c# ×3
.net-core ×1
asp.net ×1
generics ×1
javascript ×1
jquery ×1
master-pages ×1
orm ×1
protobuf-net ×1
stylecop ×1