我有基础抽象Goods类和继承Book类.
abstract class Goods
{
public decimal weight;
string Title, BarCode;
double Price;
public Goods(string title, string barCode, double price)
{
Title = title;
BarCode = barCode;
Price = price;
}
}
abstract class Book : Goods
{
protected int NumPages;
public Book(string title, string barCode, double price, int numPages)
: base(title, barCode, price)
{
NumPages = numPages;
weight = 1;
}
public override void display()
{
base.display();
Console.WriteLine("Page Numbers:{0}", NumPages);
}
}
Run Code Online (Sandbox Code Playgroud)
我应该写title, …
我想做adapter模板。
Move()中有错误AutoToTravelAdapter;方法 我该如何override和inherit运输方法?我尝试使用虚拟但它不起作用。我在两个适配器中更改为 public override void Move() 并且有效!谢谢,佐哈尔·佩莱德!
using System;
namespace Adapter
{
class Program
{
static void Main(string[] args)
{
Traveller traveller = new Traveller();
Transport camelTransport = new CamelToTravelAdapter();
Transport autoTransport = new AutoToTravelAdapter();
traveller.Travel(camelTransport);
traveller.Travel(autoTransport);
Console.Read();
}
}
public class Transport
{
virtual public void Move() { Console.WriteLine("trans Moves"); }
}
class Auto
{
public void Drive()
{
Console.WriteLine("Car drive");
}
}
class Traveller
{
public void …Run Code Online (Sandbox Code Playgroud) System.InvalidOperationException: The instance of entity type 'ProjectAssignment' cannot be tracked because another instance with the same key value for {'ProjectID'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.Add(TKey key, InternalEntityEntry entry)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.St
Run Code Online (Sandbox Code Playgroud)
我制作了一个带有Worker(ID和其他列)和Project(ID和其他列)Entity和ProjectAssignment(许多ID分配给许多Workers)的项目。但是,当我尝试获取ProjectAssignment数据时,会出现Application Insights中的错误。奇怪的是,该ID并未更早出现。
这是https://github.com/Streamc/ContosoObserve1/tree/master/Proj_s
context.Database.EnsureCreated();
var ProjectAssignments = new ProjectAssignment[]
{
new ProjectAssignment
{
ProjectID = Projects.Single( i => i.ID == 1).ID,
WorkerID …Run Code Online (Sandbox Code Playgroud) Either target .NET Core 2.0 or lower, or use a version of the .NET SDK that supports .NET Core 2.1. Microsoft.AspNetCore.Identity.Test C:\Program Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference
Run Code Online (Sandbox Code Playgroud)
我尝试构建Microsoft示例https://github.com/aspnet/Identity/tree/dev/samples/IdentitySample.Mvc
我安装了Netcore SDK 2.1.4
dotnet --info 显示2.0.5
为什么会出现错误?
我尝试在 SQL Server 中执行 SQL-1999 样式递归
CREATE TABLE addressparts(
AddrPartId INTEGER NOT NULL,
ParentID INTEGER NOT NULL,
AddrPartTypeId VARCHAR(30),
Name VARCHAR(30),
constraint PK_OBJECTS primary key (AddrPartId))
insert into addressparts values (1, 0, 'country','Zimbabwe');
insert into addressparts values (2, 1, 'city','zi');
insert into addressparts values (3, 2, 'subcity','kalkli');
insert into addressparts values (4, 2, 'subcity','kalkli1');
Run Code Online (Sandbox Code Playgroud)
我想要选择递归查询
WITH
Rec (AddrPartId, ParentID, AddrPartTypeId, name)
AS (
SELECT AddrPartId, ParentID, AddrPartTypeId, name FROM addressparts
UNION ALL
SELECT Rec.AddrPartId, Rec.ParentID, rec.AddrPartTypeId, Rec.name
FROM Rec
inner …Run Code Online (Sandbox Code Playgroud) 我尝试为Visual Studio 2017做Razor ContosoUniversity(最初在ContsoObserve中重命名)并得到错误我的.csproj是
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Utils" Version="2.0.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.NETCore.App" Version="2.0.4" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" />
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
我在NuGet中安装了所有软件包
当我
dotnet aspnet-codegenerator razorpage -m Student -dc SchoolContext -udl -outDir Pages\Students --referenceScriptLibraries
Run Code Online (Sandbox Code Playgroud)
得到
建立失败.Data\SchoolContext.cs(5,17):错误CS0234:命名空间"Microsoft"中不存在类型或命名空间名称"EntityFrameworkCore"(您是否缺少程序集引用?)[C:\ Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Pages\About.cshtml.cs(5,32):错误CS0234:命名空间"Microsoft.AspNetCore.Mvc"中不存在类型或命名空间名称"RazorPages"(是你吗?缺少程序集引用?)[C:\ Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Pages\Contact.cshtml.cs(5,32):error CS0234:类型或命名空间名称'RazorPages'在命名空间 'Microsoft.AspNetCore.Mvc'(?是否缺少的组件参考)不存在[C:\用户\ STR \源\回购\ ContosoObserve\ContosoObserve\ContosoObserve.csproj]页\ Error.cshtml.cs( 6,32):错误CS0234:命名空间"Microsoft.AspNetCore.Mvc"中不存在类型或命名空间名称"RazorPages"(您是否缺少程序集引用?)[C:\ Users\STR\source\repos\Conto soObserve\ContosoObserve\ContosoObserve.csproj] Pages\Index.cshtml.cs(6,32):错误CS0234:命名空间"Microsoft.AspNetCore.Mvc"中不存在类型或命名空间名称"RazorPages"(你错过了吗?程序集引用?)[C:\ Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Program.cs(7,28):error CS0234:命名空间中不存在类型或命名空间名称"Hosting" 'Microsoft.AspNetCore'(您是否缺少程序集引用?)[C:\ Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Program.cs(8,28):error CS0234:类型或命名空间名称"配置"在名称空间"Microsoft.Extensions"中不存在(您是否缺少程序集引用?)[C:\ Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Program.cs(9, 28):错误CS0234:命名空间"Microsoft.Extensions"中不存在类型或命名空间名称"Logging"(您是否缺少程序集引用?)[C:\ Users\STR\source\repos\C ontosoObserve\ContosoObserve\ContosoObserve.csproj] Startup.cs(5,28):错误CS0234:命名空间"Microsoft.AspNetCore"中不存在类型或命名空间名称"Builder"(您是否缺少程序集引用?)[C :\ Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] …
Here is example of Albahari
public class Stack
{
int position;
object[] data = new object[10]; // Why 10 nor 1?
public void Push (object obj) { data[position++] = obj; } //do not understood; Why there is no loop
public object Pop() { return data[--position]; } //do not understood Why there is no loop
}
Stack stack = new Stack();
stack.Push ("sausage");
string s = (string) stack.Pop(); // Downcast, so explicit cast is needed
Console.WriteLine (s); // sausage
Run Code Online (Sandbox Code Playgroud)
I rewrote …
我有
CmdString = "insert into Team_table (name1, name2, result1, result2) (select t1.name,t2.name,NULL,NULL from teams t2 cross join teams t1)";
Run Code Online (Sandbox Code Playgroud)
我把它分成两列,按压输入就像输入一样
CmdString = "insert into Team_table (name1, name2, result1, result2)
(select t1.name,t2.name,NULL,NULL from teams t2 cross join teams t1)";
Run Code Online (Sandbox Code Playgroud)
errore出现了
我怎么解决这个问题?
c# ×6
asp.net-core ×2
abstract ×1
adapter ×1
asp.net ×1
inheritance ×1
object ×1
overriding ×1
razor ×1
recursion ×1
sql ×1
sql-server ×1
sqlcommand ×1