我尝试在 stackoverflow 上搜索此内容,但找不到答案。
我正在简化我的问题,以便它更容易阅读,如果需要,我会扩展。
我有一个员工 SQL 表NAME, ADDRESS, HIRE_DATE,我们最近添加了一个REHIRE_DATE来跟踪新员工何时重新加入公司。我想编写一个 SQL 搜索来提取NAME, ADDRESS他们最近的雇用日期。如果他们是重新雇用的,我会使用该REHIRE_DATE字段,但如果他们是原来的,则使用该HIRE_DATE字段。我猜这是一个在现场CASE寻找的声明,但除此之外我迷失了。NULLREHIRE_DATE
我有一个ListView包含三列的,并且已在中添加了4条记录ListView。我想获取每个记录的第二列值的值。如何执行呢?
下面的代码产生错误:
LINQ to Entities无法识别方法
System.String GenerateSubscriptionButton(Int32)方法,并且此方法无法转换为存储表达式.
如何在LINQ to Entities中创建正确的自定义方法?
var model = _serviceRepository.GetProducts().Select(p => new ProductModel
{
Id = p.Id,
Name = p.Name,
Credits = p.Credits,
Months = p.Months,
Price = p.Price,
PayPalButton = GenerateSubscriptionButton(p.Id)
});
private string GenerateSubscriptionButton(int id)
{
return new PaymentProcessor.PayPalProcessor().CreateSubscriptionButton(id);
}
Run Code Online (Sandbox Code Playgroud) 我的代码也可以在这里找到.
这段代码可行(但代码重复很多):
Employee::Employee(const Employee& x)
{
name=new char [strlen(x.name)+1];
strcpy(name, x. name);
strcpy(EGN, x.EGN);
salary=x.salary;
}
void Employee::operator=(const Employee& x)
{
delete[] name;
name=new char [strlen(x.name)+1];
strcpy(name, x. name);
strcpy(EGN, x.EGN);
salary=x.salary;
}
Employee::Employee(char* n, char* e, double s)
{
name = new char [strlen(n)+1];
strcpy(name, n);
strcpy(EGN, e);
salary=s;
}
Run Code Online (Sandbox Code Playgroud)
以下是我试图避免三次写同样的事情......但它不起作用.是不是可以缩短代码?
Employee::Employee(char* n, char* e, double s)
{
name = new char [strlen(n)+1];
strcpy(name, n);
strcpy(EGN, e);
salary=s;
}
Employee::Employee(const Employee& x)
{
Employee(x.name, x.EGN, x.salary);
} …Run Code Online (Sandbox Code Playgroud) 我有一个类,它应该充当实体类(如 DDD 中)。它基本上看起来像这样:
public class Page
{
protected String Name;
protected String Description;
protected Dictionary<int, IField> Fields = new Dictionary<int, IField>();
protected Page SetName(String name)
{
this.Name = name;
return this;
}
protected Page SetDescription(String description)
{
this.Description = description;
return this;
}
public Page AddField(IField field)
{
this.Fields.add(xxx, Field); //xxx = just some id
return this;
}
}
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,这是一个有效的实体类吗?
我需要保持方法链接,所以请不要对此进行太多详细说明(即使您认为这是错误的)。
我主要关心的是,实体类是否可以包含方法,例如 getter 和 setter?尤其是像AddField?这样的方法
该AddField方法采用 类型的对象IField。我将其存储在班级内的字典中Page。那么这就是一个总和,对吗?
这不会改变实体的状态,使其不是真正的实体类吗?
还是就这样就可以了?
我从AdventureWorks数据库生成了实体模型; 现在我想删除app.config中的连接字符串并在运行时设置它.在Model1.Context.cs文件中,我将构造函数设置为
public AdventureWorksEntities(string str)
: base("name=AdventureWorksEntities")
{
this.Database.Connection.ConnectionString = str;
}
Run Code Online (Sandbox Code Playgroud)
并在program.cs文件中
EntityConnectionStringBuilder ecsb = new EntityConnectionStringBuilder();
ecsb.Metadata = @"res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl";
ecsb.Provider = @"System.Data.SqlClient";
ecsb.ProviderConnectionString =
@"data source=.\sqlexpress;initial catalog=AdventureWorks;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework";
using (var ent = new AdventureWorksEntities(ecsb.ConnectionString))
{
Console.WriteLine(ent.Database.Connection.ConnectionString);
var add = ent.Addresses;
foreach (var ad in add)
{
Console.WriteLine(ad.City);
}
}
Console.ReadKey();
Run Code Online (Sandbox Code Playgroud)
现在它说没有找到元数据关键字.如何在运行时为entityframework设置连接字符串?
我刚开始尝试学习C#.到目前为止,我已阅读了大约50篇教程,并认为我有很好的理解.显然我错了.我一直在msdn.microsoft.com的C#程序员参考上做了很多阅读,但它似乎不是教程的最佳来源.
我真的想完成最简单的任务.试图理解变量,操作和输入.我来自Web编程,并希望将PHP脚本转换为桌面应用程序,因此我正在尝试学习C#的基础知识,我想我可能需要学习不同的语言.
基本上,我有一个文本框和一个按钮.单击该按钮时,我想检查文本框中的文本,看它是否与某个字符串匹配.然后显示带消息的消息框.
private void btnClick_Click(object sender, EventArgs e) {
if(txtCL.Text == "one") {
bool myTest = true;
} else {
bool myTest = false;
}
if(myTest == true) {
MessageBox.Show("You entered the correct password.", "Important Message");
} else {
MessageBox.Show("The password you entered is not correct.", "Incorrect Input");
}
}
Run Code Online (Sandbox Code Playgroud)
如果有人能指出我更好的教程,我会非常感激,所以我可以更快地学习.微软的文档真的没有教我任何东西.
我为这个愚蠢的问题道歉,随时称我为白痴.
我想创建一个带有圆角和渐变颜色的自定义组合框。我Button通过重写OnPaint方法实现了相同的功能。但是它不起作用ComboBox。任何帮助将不胜感激。
OnPaint下面给出了我用于覆盖的代码:
protected override void OnPaint(PaintEventArgs paintEvent)
{
Graphics graphics = paintEvent.Graphics;
SolidBrush backgroundBrush = new SolidBrush(this.BackColor);
graphics.FillRectangle(backgroundBrush, ClientRectangle);
graphics.SmoothingMode = SmoothingMode.AntiAlias;
Rectangle rectangle = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1);
GraphicsPath graphicsPath = RoundedRectangle(rectangle, cornerRadius, 0);
Brush brush = new LinearGradientBrush(rectangle, gradientTop, gradientBottom, LinearGradientMode.Horizontal);
graphics.FillPath(brush, graphicsPath);
rectangle = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 100);
graphicsPath = RoundedRectangle(rectangle, cornerRadius, 2);
brush = new LinearGradientBrush(rectangle, gradientTop, gradientBottom, LinearGradientMode.Horizontal); …Run Code Online (Sandbox Code Playgroud) 计划#1:
#include<stdio.h>
#include<stdlib.h>
char *getString()
{
char str[] = "GfG";
printf("%s \n", str);
return str;
}
int main()
{
printf("%s", getString());
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
GfG
GfG
Run Code Online (Sandbox Code Playgroud)
计划#2:
#include<stdio.h>
#include<stdlib.h>
char *getString()
{
char str[] = "GfG";
return str;
}
int main()
{
printf("%s", getString());
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
(垃圾值)
请解释为什么因为只有一个printf语句输出不同.具体描述是什么?
在Visul Studio的对象浏览器中,我们可以看到许多名称空间(例如System,System.Collections)System.IO都位于单个程序集中mscorlib.dll.
我想知道它们是如何在多个组件中分开的:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework
Run Code Online (Sandbox Code Playgroud)
我的意思是,我们将所有这些名称空间作为单独的DLL(例如System.Collections.dll),我们也有mscorlib.dll.