我需要从SQL Server 2012的现有数据库中获取.sql文件.这是可能的,因为我在导出选项中看到的只是分隔文件.
例如,我有table1有30条记录.我需要一个类似下面的文件.(我知道我的语法不正确,但你应该明白这一点).
CREATE TABLE table1 (
INSERT INTO table1 values (
.......)
Run Code Online (Sandbox Code Playgroud) 我有一个发送多封电子邮件的MVC 4应用程序.例如,我有一个用于提交订单的电子邮件模板,一个用于取消订单的模板等...
我有Email Service多种方法.我的控制器调用如下所示的Send方法:
public virtual void Send(List<string> recipients, string subject, string template, object data)
{
...
string html = GetContent(template, data);
...
}
Run Code Online (Sandbox Code Playgroud)
该Send方法调用GetContent,这是导致该问题的方法:
private string GetContent(string template, object data)
{
string path = Path.Combine(BaseTemplatePath, string.Format("{0}{1}", template, ".html.cshtml"));
string content = File.ReadAllText(path);
return Engine.Razor.RunCompile(content, "htmlTemplate", null, data);
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
相同的密钥已用于另一个模板!
我GetContent应该在我的方法中添加一个新参数TemplateKey并使用该变量而不是总是使用htmlTemplate?然后new order email template可以使用newOrderKey和CancelOrderKey用于取消订单的电子邮件模板?
我正在尝试编写一个查询来让系统中的用户拥有他/她的所有角色.用户和角色之间存在多对多关系.木匠表是SystemUserUserRole列UserId和RoleId.我的模型如下:
SystemUser模型
[Key]
public int UserId { get; set; }
[Required]
[MaxLength(75)]
public string FirstName { get; set; }
[Required]
[MaxLength(75)]
public string LastName { get; set; }
[Required]
[MaxLength(15)]
public string Phone { get; set; }
[Required]
[MaxLength(250)]
public string Email { get; set; }
public virtual List<UserRole> UserRoles { get; set; }
Run Code Online (Sandbox Code Playgroud)
UserRole模型
[Key]
public int RoleId { get; set; }
[Required]
[MaxLength(250)]
public string RoleName { get; set; }
public virtual …Run Code Online (Sandbox Code Playgroud) 我正在使用:bootstrap.min、jquery-1.10.2、jquery-ui-1.10.4.min。使用这些库我想提供拖放功能。Bootstrap 按钮应该是可拖动的,但事实并非如此。控制台日志清晰。jQuery 和 jQuery UI 已加载并可以工作。
脚本:
<script type="text/javascript">
$(document).ready(function() {
$('.btn.verticalButton').draggable({
connectToSortable: '.container',
containment: 'document',
helper: function(){ return $(html); }
});
$("#droppable").droppable({
drop: function (event, ui) {
$(ui.draggable).clone().appendTo(this);
$(ui.draggable).remove();
}
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
网页:
<div class="container">
<div class="row">
<div class="col-sm-6 col-md-6">
<div class="panel panel-info text-center">
<div class="panel-heading text-center">Buttons</div>
<div class="btn-group-vertical">
<button class="btn verticalButton">B1</button>
<button class="btn verticalButton">B2</button>
<button class="btn verticalButton">B3</button>
</div>
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 我希望我的站点上的管理员能够锁定成员,但默认mvc成员身份的IsLockedOut()是readonly.我读到我需要创建一个自定义成员资格提供程序,但我不完全确定这意味着什么.我是否需要使用membershipUser属性创建新模型?如果可能,我不想在数据库中创建新表.
这是我的lockUser方法的代码:
public static void LockUser(this MembershipUser user)
{
using (var db = new MovieContext())
{
Guid userid = (Guid)user.ProviderUserKey;
MembershipUser member = Membership.GetUser(userid);
member.IsLockedOut = true;
member.LastLockoutDate = DateTime.Now;
db.SaveChanges();
}
}
Run Code Online (Sandbox Code Playgroud) c# asp.net-mvc asp.net-membership custom-membershipprovider asp.net-mvc-3
我是单元测试的新手,我想为我的搜索功能创建一个测试。我的服务层看起来像:
public class EmployeeService: BaseService, IEmployeeService
{
public EmployeeService(IUnitOfWork unitOfWork) : base(unitOfWork)
{
_employeeRepo = unitOfWork.EmployeeRepository;
}
public IEnumerable<Employee> Search(Employee advancedSearch, int[] divisionIds, bool showInactive, int pageSize, int? page)
{
return _employeeRepo.Search(advancedSearch, divisionIds, showInactive, pageSize, page);
}
}
Run Code Online (Sandbox Code Playgroud)
单元测试:
[Test]
public void SearchShouldFilterActiveEmployees()
{
var employees = new List<Employee>
{
new Employee { EmployeeId = 105, FirstName = "John", LastName = "Smith", IsActive = true },
new Employee { EmployeeId = 162, FirstName = "John", LastName = "Doe", IsActive = …Run Code Online (Sandbox Code Playgroud) 我有一般的查询,例如:
SELECT col1, col2, col3, col4
FROM Table1 AS t1
GROUP BY col1, col2, col3, col4
Run Code Online (Sandbox Code Playgroud)
它将返回一个类似于以下内容的表:
col1 col2 col3 col4
data1 data2 data3 data4
data1 data2 data3 data5
data10 data11 data12 data13
data10 data11 data12 data14
data10 data11 data12 data15
Run Code Online (Sandbox Code Playgroud)
我需要获取col1的计数以显示data1返回两次而data10返回三次.该表应如下所示:
col1 col2 col3 col4 Count
data1 data2 data3 data4 2
data1 data2 data3 data5 2
data10 data11 data12 data13 3
data10 data11 data12 data14 3
data10 data11 data12 data15 3
Run Code Online (Sandbox Code Playgroud)
我在select语句中尝试了count(*),但这不起作用.
我正在尝试初始化IEnumerable,但我收到错误
无法将类型'System.Collections.Generic.IEnumerable <>'隐式转换为System.Collections.Generic.IEnumerable.KeyValuePair>'.
用代码
IEnumerable<KeyValuePair<Guid, String>> users;
if (Roles.IsUserInRole("Administrator"))
{
users = _systemUserCommand.LookupUsersInRole(null, query)
.Select(s => new { s.SystemUserId, Text = string.Format("{0} {1}", s.FirstName, s.LastName) });
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
c# ×3
sql-server ×2
asp.net-mvc ×1
dapper ×1
jquery ×1
jquery-ui ×1
moq ×1
nunit ×1
razorengine ×1
sql ×1
unit-testing ×1