当我使用Entity Framework迁移的Add-Migration命令时,我得到以下异常:
System.NullReferenceException: Object reference not set to an instance of an object. at System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetFileName(Project project, String projectItemName) at System.Data.Entity.Migrations.MigrationsCommands..ctor(Object project, Object startUpProject, String configurationTypeName, String connectionStringName, String connectionString, String connectionProviderName, PSCmdlet cmdlet)
任何见解?
假设我有两个类:
class Employee
Run Code Online (Sandbox Code Playgroud)
和
class AdvancedEmployee:Employee
Run Code Online (Sandbox Code Playgroud)
我知道这样的事情不会起作用,因为我不能低估C#:
var employee = new Employee();
var advanced = employee as AdvancedEmployee;
Run Code Online (Sandbox Code Playgroud)
我的问题是:如何以有效的方式完成垂头丧气?实际上我在AdvancedEmployee上有一个构造函数,它将Employee作为参数并使用它来注入它的值,基本上是克隆.
更新
为了解决可能重复的数据,我改变了方法,现在AdvancedEmployee包含了一个员工而不是一个员工.例:
class Employee;
class AdvancedEmployee
{
private employee
public AdvancedEmployee(Employee employee){
this.employee = employee
}
}
Run Code Online (Sandbox Code Playgroud) 假设我正在编写tcp代理代码.我正在读取传入的流并写入输出流.我知道Stream.Copy使用缓冲区,但我的问题是:Stream.Copy方法在从输入流中获取下一个块时是否写入输出流,或者它是一个循环,如"从输入读取块,将块写入输出,从输入中读取块等"?
首先使用代码我设计了3个类:
class User {
public Int32 ID {get;set;}
public virtual ICollection<UserCityDetail> {get;set;}
public Int32 MainCityID {get;set;}
public UserCityDetail MainCityDetail {get;set;}
}
class City{
public Int32 ID {get;set;}
...
}
class UserCityDetail{
[Key, Column(Order = 0)]
public Int32 UserID {get;set;}
[Key, Column(Order = 1)]
public Int32 CityID{get;set;}
...
}
Run Code Online (Sandbox Code Playgroud)
所以基本上我有一个用户在几个城市有不同的细节.UserCityDetail的用户ID是PK和FK.我也希望直接参考主要的城市细节,所以我在用户上放置了一个城市ID FK.
如何将用户ID和MainCityID配置为像MainCityDetail的FK一样?