如何以编程方式创建数据库以及我需要执行此操作的最少信息是什么?
请不要"SQL Server管理对象API"建议.
这是实体框架:
var department = _context.Departments
.Include(dep => dep.Employees.Select(emp => emp.ContactTypes))
.SingleOrDefault(d => d.Id == departmentId);
Run Code Online (Sandbox Code Playgroud)
在这里,我希望返回一个部门,其中包含所有相关员工以及每个员工的所有联系类型.
这是ormlite servicestack:
我不知道.当我查看docu/samples时:https://github.com/ServiceStack/ServiceStack.OrmLite
他们写:
现在,Expression支持可以使用强类型API来满足大多数简单查询.对于任何更复杂的事情(例如,使用表连接的查询),您仍然可以轻松地回退到原始SQL查询,如下所示.
我已经看到有一个JoinSqlBuilder类,但我不认为它可以返回嵌套集合.
也许我想要的是不可能的,但也许我可以做一个妥协,比如让所有员工都参加部门会议.然后我记忆员工并获取某个employeeId的所有联系人类型.创建层次结构并分配列表仍然是我的工作.
但我希望有一个更短的解决方案.
什么也没关系,当查询但它可能看起来像返回一个具有3个平面属性的对象(动态?):Department,Employees,ContactTypes并为我的DTO分配thoese属性.
我正在使用EF 6.1,我使用代码优先方法与现有数据库一起使用生产环境中的数据.
是否可以迁移模型更改并保留现有客户的数据?
使用Angularjs 1.x,您可以轻松地在编辑/读取模式之间的按钮单击上切换html模板.ng-include指令是关键.
<table>
<thead>
<th>Name</th>
<th>Age</th>
<th></th>
</thead>
<tbody>
<tr ng-repeat="contact in model.contacts" ng-include="getTemplate(contact)">
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
get getTemplate函数执行以下代码:
$scope.getTemplate = function (contact) {
if (contact.id === $scope.model.selected.id) return 'edit';
else return 'display';
};
Run Code Online (Sandbox Code Playgroud)
这再次导致其中一个模板在UI中处于活动状态:
显示
<script type="text/ng-template" id="display">
<td>{{contact.name}}</td>
<td>{{contact.age}}</td>
<td>
<button ng-click="editContact(contact)">Edit</button>
</td>
</script>
Run Code Online (Sandbox Code Playgroud)
编辑
<script type="text/ng-template" id="edit">
<td><input type="text" ng-model="model.selected.name" /></td>
<td><input type="text" ng-model="model.selected.age" /></td>
<td>
<button ng-click="saveContact($index)">Save</button>
<button ng-click="reset()">Cancel</button>
</td>
</script>
Run Code Online (Sandbox Code Playgroud)
https://jsfiddle.net/benfosterdev/UWLFJ/
对于Angular 2 RC 4,不存在n-include.
如何使用Angular 2 RC4进行相同的功能?
我想将MOQ .net库添加到.NET 4.0项目中.我收到一条错误消息,我应该将项目转换为小于4.0的项目.由于其他项目依赖性,我还需要使用.NET 4.0.
如何在VS2010中使用MOQ与.NET 4.0项目一起工作?
我无法从c#代码访问我的sql server连接.我收到此错误:
Sql异常:没有进程在管道的另一端
那是app.config中的连接字符串:
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=BELLA\SQLEXPRESS;Initial Catalog=TLP;User Id=pascal;Password=test;Pooling=False"/>
Run Code Online (Sandbox Code Playgroud)
当我使用Windows身份验证时:Integrated Security = True;
然后我可以连接到数据库.
但是我不能使用Windows身份验证,因为sql连接的打开是在作为LocalSystem运行的Windows服务中完成的.当我这样做时,我收到此错误:
登录失败.用户'NT AUTHORITY\SYSTEM'登录失败
这是我第一次在sql管理工作室创建登录+用户,所以我几乎可以肯定我做错了什么,这是我的错.
这就是我做的:
1)使用sql authentication user:pascal和password:test在服务器的安全文件夹中创建一个新的登录名.
2)去我的数据库并在安全文件夹中用user:pascal和login:pascal和schema创建一个新用户:dbo
3)我忘记了什么吗?
其他人的解决方案:
1)我也试过这个链接,但没有运气我的suspect_pages表上的Sql Select是空的.
2)我的Sql Server网络配置在tcp/ip上有ENABLED,命名管道和共享内存设置.
1到3号没有任何帮助.
所有这些都在我的本地机器上完成.没有网络在这里.
我有一个接受键和值的方法.两个变量都可以具有动态内容.
key =>是一个动态字符串,可以是所有类似例如"LastSentDate"
value =>是一个对象,可以是所有的东西,例如"2014-10-10"
因为键是一个动态值,如"LastSentDate"或任何键传递给方法然后我希望json属性是键字符串的值,而不是字面上键自己...
public void SetRowVariable(string key, object value)
{
var obj = new { key = value }; // key property is literally taken maybe anonym object is not a good idea?
string jsonString = JsonConvert.SerializeObject(obj);
// jsonString should have that output => "{ "LastSentDate": "2014-10-10" }"
}
Run Code Online (Sandbox Code Playgroud)
我如何序列化我得到希望输出的obj?
"key"属性也必须包含特殊的字符,如"!"§$%&/()=?"`
我遗憾地使用.NET 3.5.
我可以将数据发送到服务器,但仅当我使用FromBody-Attribute时.
为什么json数据不会使用Post自动从Body中读取?
后端web api
[HttpPost]
public async Task<IActionResult> Post([FromBody]CreateSchoolyearRequestDTO dto)
{
}
Run Code Online (Sandbox Code Playgroud)
前端angularjs
this.createSchoolyear = function (schoolyear) {
var path = "/api/schoolyears";
return $http({
url: path,
method: "POST",
data: schoolyear,
contentType: "application/json"
}).then(function (response) {
return response;
});
};
Run Code Online (Sandbox Code Playgroud) 我是EF7的新手.我知道这是一个重复的问题:
但是在你想要关闭这个问题之前等待......继续阅读
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddScoped<TestRepository, TestRepository>();
Run Code Online (Sandbox Code Playgroud)
现在我在我的EF项目的cmd窗口上运行dnx ef database update命令并得到以下错误:
C:\TGB.DataAccess>dnx ef database update
System.InvalidOperationException: No database providers are configured. Configure a database provider by overriding OnConfiguring in your DbContext class or in the AddDbContext method when setting up services.
bei Microsoft.Data.Entity.Internal.DatabaseProviderSelector.SelectServices(ServiceProviderSource providerSource)
bei Microsoft.Data.Entity.Internal.DbContextServices.<>c__DisplayClass6_0.<Initialize>b__0()
bei Microsoft.Data.Entity.Internal.LazyRef`1.get_Value()
bei Microsoft.Data.Entity.Internal.DbContextServices.get_DatabaseProviderServices()
bei Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.<>c.<AddEntityFramework>b__0_8(IServiceProvider p)
bei Microsoft.Extensions.DependencyInjection.ServiceLookup.FactoryService.Invoke(ServiceProvider provider)
bei Microsoft.Extensions.DependencyInjection.ServiceProvider.ScopedCallSite.Invoke(ServiceProvider provider)
bei Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass12_0.<RealizeService>b__0(ServiceProvider provider)
bei Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
bei Microsoft.Extensions.DependencyInjection.ServiceProviderExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
bei Microsoft.Extensions.DependencyInjection.ServiceProviderExtensions.GetRequiredService[T](IServiceProvider provider) …Run Code Online (Sandbox Code Playgroud) 当我使用EF 6运行此方法时,学生已更新!
public async Task Update(Student student)
{
context.Entry(student).State = EntityState.Modified;
await context.SaveChangesAsync();
}
Run Code Online (Sandbox Code Playgroud)
当我用EF 7运行这个方法时,数据库中没有任何变化!
我错了什么?我不想先检索实体来更新它!
UPDATE
我在SaveChanges周围放了一个try/catch并得到了这个错误信息:
The UPDATE statement conflicted with the FOREIGN KEY constraint "FK_Students_Schoolclasses_SchoolclassId". The conflict occurred in database "TGBData", table "dbo.Schoolclasses", column 'Id'.
The statement has been terminated.
Run Code Online (Sandbox Code Playgroud)
当我将其中一个属性(例如Student.SchoolclassId)设置为外键时,将WHOLE实体状态设置为已修改时,是否存在问题?
更新2
public class Student
{
public Student()
{
StudentsTests = new HashSet<StudentTest>();
StudentsSubjects = new HashSet<SubjectStudent>();
}
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { …Run Code Online (Sandbox Code Playgroud)