我想在所有数据库中列出所有表名,列名,模式名和所有者,并编写下面的代码.我不知道从何处获取架构所有者详细信息以添加到我的查询中.请帮忙 .
select c.name as colomn_name , t.name as table_name , s.name as schema_name
from sys.columns c
inner join sys.tables t on c.object_id=t.object_id
INNER JOIN sys.schemas AS s ON t.[schema_id] = s.[schema_id]
Run Code Online (Sandbox Code Playgroud) 是否可以从c#中的int反序列化枚举.例如,如果我有以下课程:
class Employee
{
public string Name { get; set;}
public int EmployeeTypeID { get; set;}
}
Run Code Online (Sandbox Code Playgroud)
我可以轻松地从XML创建它
<Employee>
<Name>Joe Bloggs</Name>
<EmployeeTypeID>1</EmployeeTypeID>
</Employee>
Run Code Online (Sandbox Code Playgroud)
使用这样的东西:
Employee employee = (Employee)new XmlSerializer(typeof(Employee)).Deserialize(XmlReader);
Run Code Online (Sandbox Code Playgroud)
由于涉及的工作非常少,这使我可以使用一个通用服务,通过将select命令,连接字符串和类型输入到并检索对象数组而无需进一步映射,我可以将其用于所有数据库对象.但是我已经忘记了枚举.假设现在而不是整数EmployeeType是一个枚举:
public enum EmployeeTypeEnum
{
Admin = 1,
Sales = 2
}
Run Code Online (Sandbox Code Playgroud)
所以我的班级成为:
class Employee
{
public string Name { get; set;}
public EmployeeTypeEnum EmployeeTypeID { get; set;}
}
Run Code Online (Sandbox Code Playgroud)
我可以使用相同的XML并使c#认识到xml中EmployeeTypeID的int值应该与enum的int值相对应吗?还有其他类似的问题,但没有一个非常令人满意的答案是相当陈旧的,并涉及批量更改代码.我希望有更好的解决方案......
作为一个可能的单独注释(并略微预期一些响应),使用枚举最好避免这种做法?我应该使用键值对吗?如果可能存在更改,我将始终使用键值对(或类似值),但在这种情况下,EmployeeType是固定的,永远不会更改.
我在MS SQL Server中有两个表:
dailyt
- 包含每日数据:
date val
---------------------
2014-05-22 10
2014-05-21 9.5
2014-05-20 9
2014-05-19 8
2014-05-18 7.5
etc...
Run Code Online (Sandbox Code Playgroud)
并且periodt
- 包含不定期的数据:
date val
---------------------
2014-05-21 2
2014-05-18 1
Run Code Online (Sandbox Code Playgroud)
给定一行dailyt
,我想通过添加相应的值来调整其值,periodt
最接近的日期先于或等于dailyt
行的日期.所以,输出看起来像:
addt
date val
---------------------
2014-05-22 12 <- add 2 from 2014-05-21
2014-05-21 11.5 <- add 2 from 2014-05-21
2014-05-20 10 <- add 1 from 2014-05-18
2014-05-19 9 <- add 1 from 2014-05-18
2014-05-18 8.5 <- add 1 from 2014-05-18
Run Code Online (Sandbox Code Playgroud)
我知道这样做的一种方法是连接dailyt
和 …
我试图找到一个优雅的解决方案,以SQL查询的形式解决以下问题.
新记录将插入Log表中.我需要检测我之前没见过的任何新记录(插入在最后一小时内)并生成警报(例如,这些记录的数量> 0)
ID, Url, DOB
1, site1.com/page1, "5/06/2012 20:01"
2, site2.com/page2, "5/06/2012 21:20"
3, site1.com/page1, "6/06/2012 10:05"
Run Code Online (Sandbox Code Playgroud)
如果"now"是6/06/2012 10:40 - 我看到插入了1条新记录(id = 3),但我不想生成警报,因为我们之前已经看过这个URL(id = 1) .
如果我们有4,site3.com/pageX,"6/06/2012 10:08"那么我想生成一个警报(返回计数= 1),因为这一行是在最后一小时插入的,我们还没有看到它之前.
实施它的最佳方法是什么?理想情况下没有嵌套查询
我遇到了webservices的问题.我通常的开发方法是创建如下所示的类.
namespace Project.Entities
{
public class Entity
{
//Some Members
}
}
namespace Project.Service
{
public class EntityService
{
public Project.Entities.Entity Get(int EntityID);
// More Methods to retrive Entities
}
}
Run Code Online (Sandbox Code Playgroud)
当允许应用程序/网站直接访问数据库时,这对我来说很好.我现在需要通过web服务公开Project.Service方法,例如
namespace Project.API
{
public class EntitiyWebService
{
[WebMethod()]
public Project.Entities.Entity Get(int EntityID)
{
return new Project.Service.EntityService(EntityID);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果我从另一个应用程序(使用Project.Entities)调用我的web服务,我无法转换Project.Entities.Entity
为Project.API.EntityWebService.Entity
.我想我明白为什么这不能编译,因为就编译器而言,这两个类没有任何共同之处,只有它们的名字.
我真正需要知道的是,如果我打了这个问题,因为坏的做法,如果我需要尽快开始重新设计,或者如果我不应该担心它,只是改变我引用来自Entities.Entity
于API.EntityWebService.Entity
我的应用程序(这肯定能"因为我的应用程序和我的webservice都使用相同的DLL,它只是引入了需要转换的web服务,所以我将如何创建转换方法.或者如果我错误地实施了正确的想法,或者错过了某些东西.或者以上都不是......
我已经考虑过让我的web服务返回XML并在我的应用程序中序列化结果,但这似乎是一个长期的方法,必须有一个更好的解决方案.任何建议将不胜感激.
我有这样的查询:
DECLARE @razem VARCHAR(MAX);
SELECT Ordering.orderID ,
Document.number,
(User_info.name +' '+ User_info.surname),
Ordering.dateStart,
Ordering.dateEnd ,
(
select COALESCE(' ',@razem)+sell_type.name as r
from Ordering_sell_type, Sell_type
where orderID = Ordering.orderID and
Ordering_sell_type.sell_typeID = sell_type.sell_typeID
) podz
FROM Ordering, User_info, Product_Document, Document, Document_type
WHERE Ordering.orderID = Product_document.orderID
AND Document.documentID = Document_type.documentID
AND Document.documentID = Product_document.documentID
AND Ordering.userID = User_info.userID
AND Ordering.isClosed = 1 AND Document_type.typeID = 1
GROUP BY Document.isitfiscal, Document.refDocID,
Document.number, Ordering.orderID, User_info.name,
User_info.surname, Ordering.dateStart,
Ordering.dateEnd , Ordering.isCLosed
ORDER BY Ordering.dateEnd
Run Code Online (Sandbox Code Playgroud)
在COALESCE函数中,我想获得所选订单的所有付款类型 …
我遇到的问题是这个SQL Merge命令执行时间太长了吗?它还需要30秒以上.我们正在使用MS-SQL 2012 Server.
那么,谁能告诉我MERGE声明我做错了什么以及为什么?
谢谢...
/****** Object: StoredProcedure [dbo].[spDealerAccount_VehicleSalesRecordReload] Script Date: 07/02/2014 11:02:21 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- ============================================================================
-- Author: ...
-- Create date: 07/01/2014
-- Description:
-- Either creates new or updates existing vehicle inventory record.
-- Record is updated only if ***either*** of following are met:
-- - source AccountID exists
-- - source VIN exists
-- - both source AccountID & VIN exists having no duplicate unique vehicle
-- …
Run Code Online (Sandbox Code Playgroud) 我将ListBox简化为以下XAML
<ListBox ItemsSource="{Binding Properties}"
DisplayMemberPath="Name"
SelectedItem="SelectedProperty" />
Run Code Online (Sandbox Code Playgroud)
在我的ViewModel中:
private List<Property> propertyList;
private Property selectedProperty;
public List<Property> Properties
{
get
{
return propertyList;
}
set
{
propertyList = value;
NotifyPropertyChanged("Properties");
}
}
public Property SelectedProperty
{
get
{
return selectedProperty;
}
set
{
NotifyPropertyChanged("SelectedProperty");
selectedProperty= value;
}
}
Run Code Online (Sandbox Code Playgroud)
我的列表框填充正常,但无论我尝试什么,当我在列表框中选择一个项目时,我似乎无法更新SelectedProperty.我已经尝试将其全部切换为使用ObservableCollection
而不是List
为CollectionChanged添加事件处理程序,但这没有用.
我确信我错过了一些愚蠢的东西,并且看不到树木的木头.我到达了我的系绳的末端,需要有人介入并提供帮助.
我在MSSQL 2008R2中有一个表:
ID | PinAddress ------------------------------------- 1 | 1 1 | 2 1 | 3 1 | 4 1 | 5 1 | 6 1 | 16 1 | 31 2 | 55 2 | 56 2 | 57 2 | 81 2 | 82 2 | 83 2 | 84 3 | 101 3 | 102 3 | 103 3 | 107 3 | 108 3 | 109
我想要的是当我搜索ID = 1时,我想要结果如此
1-6,16,31
当我搜索ID = 2时,我想要结果
55-57,81-84
当我搜索ID = 3时,我想要结果 …
sql-server user-defined-functions sql-server-2008 sql-server-2008-r2
我创建了一个索引视图,它连接了许多表以获得更好的性能,但是当我使用索引视图时,性能并不比以前好.当我调查执行计划时,我看不到视图和这些连接表上的索引视图之间的任何变化.
sql-server ×6
sql ×5
c# ×3
.net ×2
coalesce ×1
data-binding ×1
date ×1
enums ×1
listbox ×1
mvvm ×1
schema ×1
t-sql ×1
web-services ×1
wpf ×1