我目前正在使用最新版本的Entity Framework进行项目,我遇到了一个我似乎无法解决的问题.
在更新现有对象时,我可以相当容易地更新对象属性,直到它涉及到另一个类的引用的属性.
在下面的例子中,我有一个名为Foo的类,它存储各种属性,其中2个是其他类的实例
public class Foo
{
public int Id {get; set;}
public string Name {get; set;}
public SubFoo SubFoo {get; set}
public AnotherSubFoo AnotherSubFoo {get; set}
}
Run Code Online (Sandbox Code Playgroud)
当我使用下面的Edit()方法时,我传入了我想要更新的对象,我可以设法Name正确更新,但是我没有设法找到一种方法来更改SubFoo的属性.例如,如果SubFoo类具有属性Name,并且已更改并且在我的数据库与之间不同newFoo,则不会更新.
public Foo Edit(Foo newFoo)
{
var dbFoo = context.Foo
.Include(x => x.SubFoo)
.Include(x => x.AnotherSubFoo)
.Single(c => c.Id == newFoo.Id);
var entry = context.Entry<Foo>(dbFoo);
entry.OriginalValues.SetValues(dbFoo);
entry.CurrentValues.SetValues(newFoo);
context.SaveChanges();
return newFoo;
}
Run Code Online (Sandbox Code Playgroud)
任何帮助或指针将不胜感激.
更新:根据Slauma的评论我修改了我的方法
public Foo Edit(Foo newFoo)
{
var dbFoo = …Run Code Online (Sandbox Code Playgroud) 我遇到的问题是我无法让我的密码验证程序检查一个字符串,以确保其中一个字符为大写,一个字符为小写,它将检查整个字符串中的一个其他并根据它正在检查的语句打印错误消息.
我查看了这个网站和互联网的答案,我无法找到一个.这是功课.
以下是我目前的代码.
import java.util.Scanner;
public class password
{
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
String password;
String cont = "y";
char ch;
boolean upper = false;
boolean lower = false;
System.out.println("Setting up your password is easy. To view requirements enter Help.");
System.out.print("Enter password or help: ");
password = stdIn.next();
ch = password.charAt(0);
while (cont.equalsIgnoreCase("y"))
{
while (password.isEmpty())
{
System.out.print("Enter password or help: ");
password = stdIn.next();
}
if (password.equalsIgnoreCase("help"))
{
System.out.println("Password must meet these …Run Code Online (Sandbox Code Playgroud) 我正在尝试从parse.com实现一些代码,并且in在void之后我注意到一个关键字.
我很难过这是什么?你看到第二行了Void in
PFUser.logInWithUsernameInBackground("myname", password:"mypass") {
(user: PFUser?, error: NSError?) -> Void in
if user != nil {
// Do stuff after successful login.
} else {
// The login failed. Check error to see why.
}
}
Run Code Online (Sandbox Code Playgroud)
文档没有记录这一点.我知道in关键字用在for循环中.
有谁确认?
我正在尝试实体框架4的代码优先(EF CodeFirst 0.8),并且遇到一个问题,一个简单的模型,在Person和之间有一个1 - - > 0..1的关系Profile.以下是它们的定义方式:
public class Person
{
public int PersonId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime? DOB { get; set; }
public virtual Profile Profile { get; set; }
}
public class Profile
{
public int ProfileId { get; set; }
public int PersonId { get; set; }
public string DisplayName { get; set; }
public virtual Person …Run Code Online (Sandbox Code Playgroud) 我开始玩TypeScript,我发现它非常棒.但我感到困惑的区别*.d.ts和*.ts.他们之间有什么区别?任何人都可以用适当的例子来解释我吗?
我目前正在尝试将我收到的JSON对象转换为具有相同属性的TypeScript类,但我无法使其工作.我究竟做错了什么?
员工类
export class Employee{
firstname: string;
lastname: string;
birthdate: Date;
maxWorkHours: number;
department: string;
permissions: string;
typeOfEmployee: string;
note: string;
lastUpdate: Date;
}
Run Code Online (Sandbox Code Playgroud)
员工字符串
{
"department": "<anystring>",
"typeOfEmployee": "<anystring>",
"firstname": "<anystring>",
"lastname": "<anystring>",
"birthdate": "<anydate>",
"maxWorkHours": <anynumber>,
"username": "<anystring>",
"permissions": "<anystring>",
"lastUpdate": "<anydate>"
//I will add note later
}
Run Code Online (Sandbox Code Playgroud)
我的尝试
let e: Employee = new Employee();
Object.assign(e, {
"department": "<anystring>",
"typeOfEmployee": "<anystring>",
"firstname": "<anystring>",
"lastname": "<anystring>",
"birthdate": "<anydate>",
"maxWorkHours": 3,
"username": "<anystring>",
"permissions": "<anystring>",
"lastUpdate": "<anydate>"
});
console.log(e);
Run Code Online (Sandbox Code Playgroud)
pip install pycrypto 使用python3.5.2可以正常工作,但是由于python3.6而失败并出现以下错误:
inttypes.h(26):错误C2061:语法错误:标识符'intmax_t'
我只是学习JavaScript,似乎有很多方法可以声明数组.
var myArray = new Array()var myArray = new Array(3)var myArray = ["apples", "bananas", "oranges"]var myArray = [3]它们的区别是什么,首选方式是什么?
根据这个网站,以下两行非常不同:
var badArray = new Array(10); // creates an empty Array that's sized for 10 elements
var goodArray= [10]; // creates an Array with 10 as the first element
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,这两条线做了两件完全不同的事情.如果您想添加多个项目,那么badArray将被正确初始化,因为Javascript会足够聪明地知道您正在初始化数组而不是说明您想要添加多少元素.
作者试图说的是Array(10)创建一个精确有10个元素[10]的数组,并创建一个未定义大小的数组,第0个元素是10?或者这是什么意思?
我想在Angular 2单元测试中更改输入字段的值.
<input type="text" class="form-control" [(ngModel)]="abc.value" />
Run Code Online (Sandbox Code Playgroud)
我不能只改变ngModel因为abc对象是私有的:
private abc: Abc = new Abc();
Run Code Online (Sandbox Code Playgroud)
在Angular 2测试中,我可以模拟用户在输入字段ngModel中键入内容,以便使用用户在单元测试中输入的内容进行更新吗?
我可以毫无问题地抓住输入字段DebugElement和nativeElement输入字段.(只是设置了value对房地产nativeElement的输入域的似乎并没有工作,因为它不更新ngModel什么我为值设置).
也许inputDebugEl.triggerEventHandler可以被调用,但是我不确定给它的参数是什么它将模拟用户输入特定的输入字符串.
class A
{
public override int GetHashCode()
{
return 1;
}
}
class B : A
{
public override int GetHashCode()
{
return ((object)this).GetHashCode();
}
}
new B().GetHashCode()
Run Code Online (Sandbox Code Playgroud)
这会溢出堆栈.我怎么能叫Object.GetHashCode()的B.GetHashCode()?
编辑:B现在继承自A.
angular ×2
c# ×2
typescript ×2
arrays ×1
inheritance ×1
ios ×1
jasmine ×1
java ×1
javascript ×1
json ×1
keyword ×1
pycrypto ×1
python-3.6 ×1
swift ×1
testing ×1
unit-testing ×1
windows ×1