我有以下C#代码.它工作正常; 但是通过使用is运算符,该GetDestination()方法被多个if条件混乱.
在.Net 4.0(或更高版本)中,避免这些"if"条件的最佳方法是什么?
编辑:角色是业务模型的一部分,目标纯粹是使用该业务模型的一个特定应用程序的工件.
码
public class Role { }
public class Manager : Role { }
public class Accountant : Role { }
public class Attender : Role { }
public class Cleaner : Role { }
public class Security : Role { }
class Program
{
static string GetDestination(Role x)
{
string destination = @"\Home";
if (x is Manager)
{
destination = @"\ManagerHomeA";
}
if (x is Accountant)
{
destination = …Run Code Online (Sandbox Code Playgroud) 我使用Kendo UI MVVM - Fiddle跟随工作代码
这里复选框的模板中有一个绑定
<input type="checkbox" name="selection" data-bind="checked: isChecked"/>
Run Code Online (Sandbox Code Playgroud)
它isChecked与模型的属性绑定.
现在,我需要在用户通过提醒已选中/未选中状态和用户名单击复选框时显示警告.
我尝试使用data-bind ="checked:showAlert()"但是没有用.
我们怎样才能做到这一点?

身体
<script id="selection-table-template" type="text/x-kendo-template">
<tr>
<td data-bind="text: name"></td>
<td data-bind="text: age"></td>
<td>
<input type="checkbox" name="selection" data-bind="checked: isChecked"/>
</td>
</tr>
</script>
<script id="row-template" type="text/x-kendo-template">
<tr data-bind="visible: isChecked">
<td data-bind="text: name"></td>
<td data-bind="text: age"></td>
</tr>
</script>
<table id="selectionTable">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody data-template="selection-table-template" data-bind="source: employees"/>
</table>
<br />
<hr />
<table id="resultTable">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody data-template="row-template" …Run Code Online (Sandbox Code Playgroud) 我在SQL Server 2005. 一个订单可以有多个容器。容器可以是塑料的或木头的(未来可能会出现新类型)。
我需要列出以下列 -
OrderID, ContainerType, ContainerCOUNT and ContainerID.
Run Code Online (Sandbox Code Playgroud)
由于我还需要列出 ContainerID,因此以下分组方法将不起作用。
DECLARE @OrderCoarntainers TABLE (OrderID INT, ContainerID INT, ContainerType VARCHAR(10))
INSERT INTO @OrderCoarntainers VALUES (1,101,'Plastic')
INSERT INTO @OrderCoarntainers VALUES (1,102,'Wood')
INSERT INTO @OrderCoarntainers VALUES (1,103,'Wood')
INSERT INTO @OrderCoarntainers VALUES (2,104,'Plastic')
SELECT OrderID,ContainerType,COUNT(DISTINCT ContainerID) AS ContainerCOUNT
FROM @OrderCoarntainers
GROUP BY OrderID,ContainerType
Run Code Online (Sandbox Code Playgroud)
实现这一目标的最佳方法是什么?
注意:升级SQL Server version不是我的选择。
预期结果

我是 Azure SQL 数据库的新手。我有一个EXTERNAL DATA SOURCE如以下链接中列出的。
CREATE EXTERNAL DATA SOURCE [My_data_src] WITH (TYPE = RDBMS, LOCATION = N'myserver', CREDENTIAL = [my_cred], DATABASE_NAME = N'MyDB')
Run Code Online (Sandbox Code Playgroud)
去
在创建新的外部数据源之前,我需要查明它是否已经存在。是否有任何查询或 dmv 可以找到这个?
我有一个沉重的asp.net页面.当它渲染时,一些图像在开始时出现,然后逐渐加载其余图像.我们想摆脱这种行为.页面应仅在所有内容准备好后显示,并且应该一起显示.我们如何实现它?有什么办法我们可以要求页面等到它完全准备好了吗?
我创建了一个从ValidationAttribute派生的自定义验证器.我的undertsandng是它将为客户端脚本生成足够的元数据以自动验证(使用jquery.validate).自定义验证器在服务器端正常工作.但它不会在客户端激发错误消息.(其他默认验证器,如"StringLength"在客户端也正常工作.)我们如何纠正它?
public class Person
{
[Required(ErrorMessage = "First name required")]
public string FirstName { get; set; }
[CustomStartLetterMatch("FirstName")]
[StringLength(5,ErrorMessage = "Must be under 5 characters")]
public string LastName { get; set; }
[Range(18,50,ErrorMessage="Must be between 18 and 50")]
public int Age { get; set; }
}
public sealed class CustomStartLetterMatch : ValidationAttribute
{
private const string _defaultErrorMessage = " First letter of '{0}' must be same as first letetr of '{1}'";
private string _basePropertyName;
public CustomStartLetterMatch(string basePropertyName)
: base(_defaultErrorMessage)
{ …Run Code Online (Sandbox Code Playgroud) 我有一个使用LINQ to SQL实现的存储库.虽然我没有数据库,但我需要进行单元测试.如何为FreezeAllAccountsForUser方法编写UT?你能用手动模拟来展示一个例子吗?
注意:域对象中使用了继承映射
注意:单元测试将使用Visual Studio Team Test完成
来自@StuperUser的评论.单元测试涉及将代码与其交互的其他对象完全隔离.这意味着如果代码失败,您可以确定失败是与测试中的代码有关.要做到这一点,你必须伪造这些对象.
码
public void FreezeAllAccountsForUser(int userId)
{
List<DTOLayer.BankAccountDTOForStatus> bankAccountDTOList = new List<DTOLayer.BankAccountDTOForStatus>();
IEnumerable<DBML_Project.BankAccount> accounts = AccountRepository.GetAllAccountsForUser(userId);
foreach (DBML_Project.BankAccount acc in accounts)
{
string typeResult = Convert.ToString(acc.GetType());
string baseValue = Convert.ToString(typeof(DBML_Project.BankAccount));
if (String.Equals(typeResult, baseValue))
{
throw new Exception("Not correct derived type");
}
acc.Freeze();
DTOLayer.BankAccountDTOForStatus presentAccount = new DTOLayer.BankAccountDTOForStatus();
presentAccount.BankAccountID = acc.BankAccountID;
presentAccount.Status = acc.Status;
bankAccountDTOList.Add(presentAccount);
}
IEnumerable<System.Xml.Linq.XElement> el = bankAccountDTOList.Select(x =>
new System.Xml.Linq.XElement("BankAccountDTOForStatus",
new System.Xml.Linq.XElement("BankAccountID", x.BankAccountID),
new System.Xml.Linq.XElement("Status", x.Status)
));
System.Xml.Linq.XElement root = …Run Code Online (Sandbox Code Playgroud) 使用EntityFramework v4.1和IBM Data Server Client v9.7fp5,DB首先基于具有DATE列的预定义DB2表生成代码.在代码生成期间,DB2 DATE列将映射到.NET DateTime数据类型.
尝试INSERT连续时,收到以下错误
错误[22008] [IBM] CLI0114E日期时间字段溢出.SQLSTATE = 22008
这是有道理的,因为.NET没有DATE数据类型,只有DATETIME和那个属性会有更多的数据,那么DB2 DATE列会期望.
问题是
为什么.NET基本代码不能使用ToShortDateString()自动转换并提供DB2期望的内容?
在.NET将SQL事务提交给DB2之前,可以使用哪些方法覆盖.NET基本逻辑并在应用程序代码中转换值?
任何帮助或反馈将不胜感激.谢谢!
我有实体框架代码,如下所示.我在where条件中得到以下错误.
无法将lambda表达式转换为类型'bool',因为它不是委托类型
如何克服这个错误?这个错误的原因是什么?
static void Main(string[] args)
{
ClubCreation();
List<Club> selectedClubs = GetClubs("club1");
}
public static void ClubCreation()
{
string connectionstring = "Data Source=.;Initial Catalog=NerdDinners;Integrated Security=True;Connect Timeout=30";
using (var db = new NerdDinners(connectionstring))
{
Club club1 = new Club();
club1.ClubName = "club1";
Club club2 = new Club();
club2.ClubName = "club2";
Club club3 = new Club();
club3.ClubName = "club3";
db.Clubs.Add(club1);
db.Clubs.Add(club2);
db.Clubs.Add(club3);
int recordsAffected = db.SaveChanges();
}
}
public static List<Club> GetClubs(string clubName)
{
string connectionstring = "Data Source=.;Initial Catalog=NerdDinners;Integrated Security=True;Connect …Run Code Online (Sandbox Code Playgroud) 我试图在Windows 7中使用Eclipse创建我的第一个C++可执行程序.
#include <stdio.h>
int main( int argc, const char* argv[] )
{
printf( "arg" );
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
"'printf'这个词拼写错误".
以下是我的配置.如何克服这个错误?



c# ×4
.net ×3
asp.net ×2
jquery ×2
ajax ×1
asp.net-mvc ×1
c++ ×1
datetime ×1
db2 ×1
eclipse ×1
html5 ×1
javascript ×1
kendo-ui ×1
linq ×1
linq-to-sql ×1
multimethod ×1
mvvm ×1
odbc ×1
oop ×1
sql-server ×1
tdd ×1
unit-testing ×1