这是我的代码,非常简单......
var newUser = new User();
newUser.Id=id;
newUser.Email = email;
this.DataContext.Set<User>().Add(newUser);
this.DataContext.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
我得到的错误是一个sqlexception,this.DataContext.SaveChanges();说明:
无法将值NULL插入列'Id',表'xxxxx.dbo.Users'; 列不允许空值.INSERT失败.
我已经调试过,发现在newUser的Id和Email中有值
this.DataContext.Set<User>().Add(newUser);
如果是这种情况,该值如何变为空?
错误堆栈跟踪:
[DbUpdateException: An error occurred while updating the entries. See the inner exception for details.]
System.Data.Entity.Internal.InternalContext.SaveChanges() +204
System.Data.Entity.Internal.LazyInternalContext.SaveChanges() +23
System.Data.Entity.DbContext.SaveChanges() +20
Run Code Online (Sandbox Code Playgroud)
我无法理解或解决这个问题....
真诚地感谢任何帮助......
关心阿纳布
解
好的,感谢Ladislav指出我正确的方向:添加属性[DatabaseGenerated(DatabaseGeneratedOption.None)]解决了问题.
基表
id line_number
1 1232
2 1456
3 1832
4 2002
Run Code Online (Sandbox Code Playgroud)
我希望将值添加到新表中,以便下一行的值成为新列中的值,其中最后一行的值相同.
我需要生成的最终输出是:
id line_number end_line_number
1 1232 1456
2 1456 1832
3 1832 2002
4 2002 2002
Run Code Online (Sandbox Code Playgroud)
数据库是sql server.
任何帮助都是真诚的感谢.
谢谢
我的数据数组:
var data = [{glazed: 3.50, jelly: 4.50, powdered: 1.00, sprinkles: 3.50, age: 21, responses: 2,name:"test"},
{glazed: 2.83, jelly: 3.50, powdered: 1.83, sprinkles: 4.50, age: 22, responses: 6,name:"test"},
{glazed: 3.25, jelly: 4.75, powdered: 2.25, sprinkles: 3.50, age: 23, responses: 4,name:"test"},
{glazed: 1.50, jelly: 4.00, powdered: 2.50, sprinkles: 4.00, age: 25, responses: 2,name:"test"}];
Run Code Online (Sandbox Code Playgroud)
如果我想找到玻璃或果冻或粉末或洒水的范围用于缩放,我会使用如下代码..
var x = d3.scale.linear()
.domain(d3.extent(data, function (d) {
return d.glazed;//or jelly etc..
}))
.range([0, width]);
Run Code Online (Sandbox Code Playgroud)
我需要做些什么才能获得釉面,果冻,粉末和洒水中所有值的范围,而不是所有不是年龄,响应和名称的值.
这是因为json文件是动态创建的,所以我不知道除了年龄,响应和名称之外的键值.
所以,我的要求是它应该给我最小1.5(从上釉)和最大4.75(从果冻)
任何帮助都是真诚的感谢..
谢谢
我有一个结构对象列表
string source, string target, int count
Run Code Online (Sandbox Code Playgroud)
样本数据:
sourcea targeta 10
sourcea targetb 15
sourcea targetc 20
Run Code Online (Sandbox Code Playgroud)
我的另一个对象列表是结构
string source, int addnvalueacount, int addnvaluebcount, int addnvalueccount
Run Code Online (Sandbox Code Playgroud)
样本数据:
sourcea 10 25 35
Run Code Online (Sandbox Code Playgroud)
我希望将第二个列表更改为第一个列表结构,然后使用第一个列表进行联合all(concat).
所以结果应该如下所示:
sourcea targeta 10
sourcea targetb 15
sourcea targetc 20
sourcea addnlvaluea 10
sourcea addnlvalueb 25
sourcea addnlvaluec 35
Run Code Online (Sandbox Code Playgroud)
所有帮助都是真诚的感谢..
谢谢
在DocumentDB文档示例中,我找到了C#对象的插入.
// Create the Andersen family document.
Family AndersenFamily = new Family
{
Id = "AndersenFamily",
LastName = "Andersen",
Parents = new Parent[] {
new Parent { FirstName = "Thomas" },
new Parent { FirstName = "Mary Kay"}
},
IsRegistered = true
};
await client.CreateDocumentAsync(documentCollection.DocumentsLink, AndersenFamily);
Run Code Online (Sandbox Code Playgroud)
在我的例子中,我从应用程序客户端接收json字符串,并希望将它们插入DocumentDB而不反序列化它们.无法找到做类似事情的任何例子.
任何帮助都是真诚的感谢..
谢谢
我有一个从接口实现的方法,如下所示..
public Task CreateAsync(ApplicationUser user)
{
if (user == null)
{
throw new ArgumentNullException("user");
}
Task.Factory.StartNew(() => { Console.WriteLine("Hello Task library!"); });
//I even tried
//Task.Run(() => { Console.WriteLine("Hello Task library!"); });
}
Run Code Online (Sandbox Code Playgroud)
上面的代码给出了一个错误,并非所有代码路径都返回一个值.
以下是Microsoft 文档中的示例代码,显示了如何在控制台应用程序中使用 appsettings.json:
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
namespace ConsoleJson.Example
{
class Program
{
static async Task Main(string[] args)
{
using IHost host = CreateHostBuilder(args).Build();
// Application code should start here.
await host.RunAsync();
}
static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, configuration) =>
{
configuration.Sources.Clear();
IHostEnvironment env = hostingContext.HostingEnvironment;
configuration
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true, true);
IConfigurationRoot configurationRoot = configuration.Build();
TransientFaultHandlingOptions options = new();
configurationRoot.GetSection(nameof(TransientFaultHandlingOptions))
.Bind(options);
Console.WriteLine($"TransientFaultHandlingOptions.Enabled={options.Enabled}");
Console.WriteLine($"TransientFaultHandlingOptions.AutoRetryDelay={options.AutoRetryDelay}");
});
}
} …Run Code Online (Sandbox Code Playgroud) 我可以根据外部文件中的数据创建配置单元表。现在,我希望根据上一个表中的数据创建另一个表,并使用默认值添加其他列。
我了解可以使用CREATE TABLE AS SELECT,但是如何添加具有默认值的其他列?
这与这个问题的答案有关
以下作品.. http://jsfiddle.net/vt6v6L9u/2/
<div data-bind="foreach: retrievedUsers" >
<div>
<label data-bind="attr:{for:$index}">
Run Code Online (Sandbox Code Playgroud)
我需要将字符串连接到 $index.. http://jsfiddle.net/vt6v6L9u/4/
<div data-bind="foreach: retrievedUsers" >
<div>
<label data-bind="attr:{for:'const' + $index}">
Run Code Online (Sandbox Code Playgroud)
小提琴似乎可以工作,但是如果您检查单选按钮元素..您会发现..
<label data-bind="attr:{for:'const' + $index}" for="constfunction c(){if(0<arguments.length)return c.equalityComparer&&c.equalityComparer(d,arguments[0])||(c.O(),d=arguments[0],c.N()),this;a.i.lb(c);return d}">
Run Code Online (Sandbox Code Playgroud)
真诚感谢任何帮助
谢谢
我有一个1.2 GB的json文件,在反序列化时应该给我一个包含15 mil对象的列表.
我正在尝试对其进行反序列化的机器是具有16核和32 GB Ram的Windows 2012服务器(64位).
该应用程序已构建为x64的目标.
尽管如此,当我尝试读取json doc并将其转换为对象列表时,我将失去内存异常.当我看到任务管理器时,我发现只使用了5GB的内存.
我试过的代码如下.
一个.
string plays_json = File.ReadAllText("D:\\Hun\\enplays.json");
plays = JsonConvert.DeserializeObject<List<playdata>>(plays_json);
Run Code Online (Sandbox Code Playgroud)
湾
string plays_json = "";
using (var reader = new StreamReader("D:\\Hun\\enplays.json"))
{
plays_json = reader.ReadToEnd();
plays = JsonConvert.DeserializeObject<List<playdata>>(plays_json);
}
Run Code Online (Sandbox Code Playgroud)
C.
using (StreamReader sr = File.OpenText("D:\\Hun\\enplays.json"))
{
StringBuilder sb = new StringBuilder();
sb.Append(sr.ReadToEnd());
plays_json = sb.ToString();
plays = JsonConvert.DeserializeObject<List<playdata>>(plays_json);
}
Run Code Online (Sandbox Code Playgroud)
所有帮助都是真诚的感谢
c# ×5
.net-5 ×1
d3.js ×1
hive ×1
hiveql ×1
javascript ×1
json ×1
json.net ×1
knockout-2.0 ×1
knockout.js ×1
linq ×1
sql ×1
sql-server ×1