我有一个包含3列的数据库:
id, name, somethingelse
Run Code Online (Sandbox Code Playgroud)
这个表没有索引集,我得到"没有索引定义!" 在phpmyadmin中,
id是一个7位数的字母数字值,每行都是唯一的.
我想将Drugid设置为主键/索引(如果有的话,我不知道区别)
请详细解释,因为我是新手.
谢谢.
我需要以树型创建产品目录.
每个树节点都以ID(字符串)表示,树数据上的函数只有2:
getChild(string ID),给一个ID,得到孩子(不需要包括孩子的孩子),如果ID为null,则获取所有根节点 getParent(string ID),如果有,则返回父ID,如果是root,则返回null由于一旦树决定了,不会改变,所以我认为把所有代码放在静态中会是最好的.所以我开始尝试使用Dictionary
"id": {parent:ID, child:[id2, id3, id4....]}
Run Code Online (Sandbox Code Playgroud)
由于大约1000多个目录,我发现我很快搞砸了自己,在静态数据中出现了很多错误,并使最终结果可用.此外,现在我只写了几十个,代码看起来像混乱.
请建议以高性能创建这个简单的目录树.谢谢
我有一个 List<Item>
每个项目都有一个程序,它有一个Id.
如果项目尚未链接到某个程序,则该程序将为null.
我想按照程序的ID对所有项目进行分组
这就是我尝试过的:
var listaAgrupada = client.ListarItens(null, null, null).GroupBy(x => x.Programa.Id).ToList();
Run Code Online (Sandbox Code Playgroud)
如果所有项目都有程序,则此方法有效.但是如果程序为null,则抛出System.NullReferenceException:
Message ="对象引用未设置为对象的实例."
我相信这是因为,由于程序为空,我无法访问它的Id.
我需要所有的项目,即使他们的程序为空(我也希望它们按空程序分组),所以排除它们不是一个选项.
我想过两个可能的解决方案,但我不确定如何做任何一个:
一个会是这样的GroupBy(x => x.Programa == null || x.Programa.Id)(这是行不通的)
另一个是添加一个程序为空的空程序对象,但我不知道如何做到这一点
当然,我也对其他解决方案持开放态度
提前致谢
在asp.net中,如果使用自定义属性,通常会按原样呈现.
考虑到这个标记(注:属性,如id,name和for所有的例子作为自己生成的ID被拆除/名称详细):
<asp:TextBox runat="server" data-foo="bar" />
Run Code Online (Sandbox Code Playgroud)
在asp.net中呈现为:
<input type="text" data-foo="bar" />
Run Code Online (Sandbox Code Playgroud)
也就是说,asp.net保持data-foo不变.
复选框通常呈现如下:
<asp:CheckBox runat="server" Text="Normal" />
Run Code Online (Sandbox Code Playgroud)
呈现为:
<input type="checkbox" />
<label>Normal</label>
Run Code Online (Sandbox Code Playgroud)
但是,如果您在复选框上添加自定义属性:
<asp:CheckBox runat="server" Text="Custom attribute" data-foo="bar" />
Run Code Online (Sandbox Code Playgroud)
它呈现为:
<span data-foo="bar">
<input type="checkbox" />
<label>Custom attribute</label>
</span>
Run Code Online (Sandbox Code Playgroud)
如您所见,渲染的范围用于保存属性.如果在后面的代码中添加属性,也会发生这种情况.任何其他HtmlControl,AFAIK都不会发生这种情况.
有谁知道为什么这个范围被渲染来保存属性?
无论如何在输入标签中呈现属性?
关于相关领域部分的简要说明:
类别由四个数据组成:
因此,Male Adult Black Rooster形成一个类别.可能不存在某些组合,例如强大的螨黑带.
一名运动员与同一类别的运动员作战,如果他分类,他会与不同重量级别的运动员作战(但性别,年龄和腰带相同).
去建模.我有一个Category表,已经填充了域中存在的所有组合.
CREATE TABLE Category (
[Id] [int] IDENTITY(1,1) NOT NULL,
[AgeDivision_Id] [int] NULL,
[Gender] [int] NULL,
[BeltColor] [int] NULL,
[WeightDivision] [int] NULL
)
Run Code Online (Sandbox Code Playgroud)
A CategorySet和a CategorySet_Category,形成多对多的关系Category.
CREATE TABLE CategorySet (
[Id] [int] IDENTITY(1,1) NOT NULL,
[Championship_Id] [int] NOT NULL,
)
CREATE TABLE CategorySet_Category (
[CategorySet_Id] [int] NOT NULL,
[Category_Id] [int] NOT NULL
)
Run Code Online (Sandbox Code Playgroud)
给定以下结果集:
| Options_Id | Championship_Id | AgeDivision_Id | …Run Code Online (Sandbox Code Playgroud) 我正在使用Service Stack来实现一个简单的Web应用程序.
在这个应用程序中,我需要将一些内容"导出"到Excel ..所以这是我采取的方法:
GET方法,我读取文件并进行下载ContentType:"application/vnd.ms-excel"我在其他时候没有使用Service Stack这种方法,并且运行良好.. XLS文件具有正确的内容和一些颜色.
现在,当我使用GET方法获取文件时(即,使用浏览器访问url),文件内容很糟糕.
ServiceStack允许下载一些格式:html,csv,jsv,json,xml.
html格式显示默认报告页面,唯一有效的格式是jsv.
我的问题是:如何像普通的html文件一样下载文件?
一些代码:
public class ExcelService : RestServiceBase<Excel>
{
public override object OnGet (Excel request)
{
string file = request.nombre;
//Response.Clear();
HttpResult res = new HttpResult();
res.Headers[HttpHeaders.ContentType] = "application/vnd.ms-excel";
res.Headers[HttpHeaders.ContentDisposition] = "attachment; filename="+file+".xls";
string archivo = System.IO.File.ReadAllText("tmp/"+file+".html");
res.Response = archivo;
return res;
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢
我的团队刚收到承包商编写的代码,承包商倾向于使用类型推断var.我们的团队更喜欢使用实际类型进行显式输入(如下所示):
Type someName = new Type();
IList<TypeTwo> someOther = someClass.getStuff();
Run Code Online (Sandbox Code Playgroud)
而承包商交付
var someOther = someClass.getStuff();
Run Code Online (Sandbox Code Playgroud)
Visual Studio 2008知道推断类型是什么,正如我可以通过悬停var关键字看到的那样
我的问题是,有没有办法进行全局查找并将var替换为推断类型?
在我当前的项目中,我使用了很多责任链模式。
但是,我发现通过依赖注入配置链有点尴尬。
鉴于此模型:
public interface IChainOfResponsibility
{
IChainOfResponsibility Next { get; }
void Handle(Foo foo);
}
public class HandlerOne : IChainOfResponsibility
{
private DbContext _dbContext;
public HandlerOne(IChainOfResponsibility next, DbContext dbContext)
{
Next = next;
_dbContext = dbContext;
}
public IChainOfResponsibility Next { get; }
public void Handle(Foo foo) { /*...*/}
}
public class HandlerTwo : IChainOfResponsibility
{
private DbContext _dbContext;
public HandlerTwo(IChainOfResponsibility next, DbContext dbContext)
{
Next = next;
_dbContext = dbContext;
}
public IChainOfResponsibility Next { get; }
public …Run Code Online (Sandbox Code Playgroud) c# dependency-injection decorator chain-of-responsibility asp.net-core
我觉得我的问题很容易,但我是linq的新手......所以我在这里度过了难关
我的系统调用一个名为serviceTOP的服务,它返回一个列表itemTOP {Id, Name}.
这些ItemsTOP不在我的系统中,但用户可以选择要导入系统的itemTOP.
导入的ItemsTOP成为对象 Item { Id, IdTOP, Name }
因此,当系统调用serviceTOP时,在向用户显示它们之前,我必须从列表中过滤已导入的项目.
我们去代码:
IList<ItemsTOP> listTOP = new ServiceTOP().GetItemsTOP();
IList<Items> list = new WCFServiceClient().GetItems();
var filteredListTOP = listTOP.Select( i => i.Id ).Except( i => i.IdTOP );
Run Code Online (Sandbox Code Playgroud)
这种工作,但它返回一个只包含id的字符串列表.
我想选择TOP的id和名字.
提前致谢.
正如大家所知,在c#中捕获并重新抛出异常这种方式是邪恶的,因为它会破坏堆栈跟踪:
try
{
if(dummy)
throw new DummyException();
}
catch (DummyException ex)
{
throw ex;
}
Run Code Online (Sandbox Code Playgroud)
在不丢失堆栈跟踪的情况下重新抛出异常的正确方法是:
try
{
if(dummy)
throw new DummyException();
}
catch (DummyException ex)
{
throw;
}
Run Code Online (Sandbox Code Playgroud)
唯一的问题是我得到了很多编译警告:"变量'ex'被声明但从未使用过".如果你有很多这些,可能会在垃圾中隐藏一个有用的警告.那就是我做的:
try
{
if(dummy)
throw new DummyException();
}
catch (DummyException)
{
throw;
}
catch(AnotherException ex)
{
//handle it
}
Run Code Online (Sandbox Code Playgroud)
这似乎有效,但我想知道重新抛出未设置为变量的异常是否有任何缺点..net如何威胁这个?
提前致谢
编辑: 我已经改变了我的代码,以便更清楚我想做什么,因为有些人误解了
c# ×7
linq ×2
sql ×2
asp.net ×1
asp.net-3.5 ×1
asp.net-4.0 ×1
asp.net-core ×1
decorator ×1
indexing ×1
mysql ×1
primary-key ×1
servicestack ×1
sql-server ×1
tree ×1