小编Bee*_*ice的帖子

从表中只选择几列

我在使用c#,nhibernate和link时遇到了问题.在下面的例子中,我在BrandTable中做了一个SELECT,但我只需要"Name"和"Id"列.但它总是对表的所有列进行选择.使用EntityFramework,相同的代码生成只有这两列的选择.

如何在nhibernate中执行此操作?

 using (ISession session = MyConnection.GetCurrentSession())
        {
            var brands = from b in session.QueryOver<BrandTable>().List()
                                 orderby b.Name
                                 select new Brand {Id = b.id, Name = b.Name};

            return brands.ToList();
        }
Run Code Online (Sandbox Code Playgroud)

.net c# nhibernate

4
推荐指数
1
解决办法
1万
查看次数

如何将复选框绑定到asp net mvc中的字符串属性

我在我的课程中有一些代表真或假的字段,但它有字符串值"T"或"F".

如何将复选框绑定到这些字段?

checkbox asp.net-mvc

4
推荐指数
1
解决办法
1万
查看次数

在C#中定义私有属性,例如Typescript

C#中是否有语法允许我定义私有属性,例如Typescript?

示例:打字稿:

constructor (private field1: string) { }
Run Code Online (Sandbox Code Playgroud)

在C#中,我必须这样做:

private readonly string field1;
public MyClass(string field1)
{
    this.field1 = field1;
}
Run Code Online (Sandbox Code Playgroud)

更新1:

我正在寻找AspNet核心依赖项注入的语法糖。

c# typescript asp.net-core

4
推荐指数
1
解决办法
525
查看次数

jquery从$(this)位置选择下一个元素

我有以下剪辑我的页面:

<div class="radio-group">
<input type="radio" name="group1" checked="checked" id="option1" value="option1"/>
<label for="option1">option1</label>
<input type="radio" name="group1" id="option2" value="option2"/>
<label for="option2">option2</label>
<input type="radio" name="group1" id="option3" value="option3"/>
<label for="option3">option3</label>
<input type="radio" name="group1" id="option4" value="option4"/>
<label for="option4">option4</label>
</div>
Run Code Online (Sandbox Code Playgroud)

这个javascript代码在无线电点击后选择隐藏的输入:

$("input[type='radio']").live("change", function () {        
    var el = this.parentNode.nextElementSibling;
    el.value = this.value;
});
Run Code Online (Sandbox Code Playgroud)

我想写这一行

var el = this.parentNode.nextElementSibling;
Run Code Online (Sandbox Code Playgroud)

以jQuery的方式.谢谢.

jquery jquery-selectors

3
推荐指数
1
解决办法
3024
查看次数

如何git忽略以#符号开头的文件夹

是否可以创建一个.gitignore忽略以#?开头的文件或文件夹的文件?

例:

#DATABASE_FILES
#DOCUMENTATION
Run Code Online (Sandbox Code Playgroud)

git gitignore

3
推荐指数
1
解决办法
50
查看次数

EF core 3 之后 IDENTITY 列的变化

直到.donet core 2.2中使用的EF核心版本,在该.Add命令之后,EF用一个大的负数填充key列。

3.0 升级后,这种情况不再发生。

这是代码:

var appointment = new Appointment
{
    Date = DateTime.Today,
    ProfessionalId = schedule.ProfessionalId
};
await service.AddAsync(appointment);

string message = null;
if (service.AddLastPrescription(appointment.Id, schedule.PacienteId))
 ....
Run Code Online (Sandbox Code Playgroud)

问题是现在“appointment.Id”为零,对服务功能的调用将失败(FK 错误)。

这种行为在 3.0 中是预期的?

更新

添加异步函数

private DbSet<T> dbSet;

public async Task AddAsync(T t)
{
    await dbSet.AddAsync(t);
}
Run Code Online (Sandbox Code Playgroud)

其中 T 是 ModelBase:

public class ModelBase
{

    [Key]
    public int Id { get; set; }

    public DateTime CreatedAt { get; set; }
    public DateTime UpdatedAt { get; set; } …
Run Code Online (Sandbox Code Playgroud)

entity-framework entity-framework-core asp.net-core

3
推荐指数
1
解决办法
1430
查看次数

Rails模型递归json

我有一个菜单模型,它有相同类型的子菜单.就像是:

  • 1级
    • 等级1.1
    • 等级1.2
  • 2级
    • 等级2.1
    • ...

所以,我需要一种以递归的方式在我的json中包含所有级别的方法.

ruby ruby-on-rails

2
推荐指数
1
解决办法
2105
查看次数

MatAutocomplete 值 X 显示

我的自动完成显示具有以下定义的对象的值:

export class Person {
  id: number;
  name: string;
  cityName: string;
}
Run Code Online (Sandbox Code Playgroud)

这是自动完成模板:

<mat-form-field class="example-full-width">
  <input type="text" placeholder="Person" aria-label="Person" matInput formControlName="personId" [matAutocomplete]="auto">

  <mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn.bind(this)">
      <mat-option *ngFor="let item of filteredOptions" [value]="item">
        {{ item.name }}
      </mat-option>
  </mat-autocomplete>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)

这是 displayWith 函数:

displayFn(value?: any) {
  return value ? value.name : undefined;
}
Run Code Online (Sandbox Code Playgroud)

它有效,但绑定到此自动完成功能的 formControl 接收整个项目对象:

 {
    id: 1;
    name: "John";
    cityName: "Dallas";
 }
Run Code Online (Sandbox Code Playgroud)

如何在 formControl 中只获取“id”值?

angular-material angular

2
推荐指数
1
解决办法
2996
查看次数

在Delphi中继承一个属性

我正在使用Delphi XE3,我需要以这种方式覆盖属性,我仍然调用基类getter和一个新的类setter.

例:

TBaseClass = class
  ...
  property XML:string read GetXML write SetXML;
end ;

TNewClass = class(TBaseClass)
  ...
  property: XML .....
end;
Run Code Online (Sandbox Code Playgroud)

更新:

BaseClass位于.dcu编译文件中,因此我无法直接更改此文件.

delphi

1
推荐指数
1
解决办法
1223
查看次数

实体框架7 RC1关系

现在我更新到ASP.NET 5 RC1和Entity Framework 7 RC1,我希望在我的模型中启用关系.但我不能让这个工作.

这是我的模特:

帖子:

public class Post
{
    public int Id { get; set; }
    public string Text { get; set; }

    public virtual ICollection<Comment> Comments { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

评论:

public class Comment
{
    public int Id { get; set; }
    public string Text { get; set; }

    public int PostId { get; set; }
    public virtual Post Post { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我已经在表中手动插入了一些数据,并试图访问Comments 帖子的属性,如下所示:

var post = context.Posts.Where(x => x.Id == …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc entity-framework entity-framework-core

1
推荐指数
1
解决办法
119
查看次数

Bootstrap typeahead在MVC 5中不起作用

在我的mvc项目中,我试图实现自动完成但它不工作(打字头)我做的一切正确,但无法得到它.下面是我的代码.可以任何人帮助

<script type="text/javascript">
$(document).ready(function () {

    $("#Search").typeahead({
        source: function (query, process) {
            var countries = [];
            map = {};

            // This is going to make an HTTP post request to the controller
            return $.post('/Registration/GetPossibleLocations', { query: query }, function (data) {

                // Loop through and push to the array
                $.each(data, function (i, country) {
                    map[country.Name] = country;
                    countries.push(country.Name);
                });

                // Process the details
                process(countries);
            });
        },
        updater: function (item) {
            var selectedShortCode = map[item].ShortCode;

            // Set the text to our …
Run Code Online (Sandbox Code Playgroud)

javascript asp.net-mvc jquery bootstrap-typeahead twitter-bootstrap-3

0
推荐指数
1
解决办法
6275
查看次数

更新用户名和电子邮件

在Asp.net Core项目中,我使用下面的代码更改用户名和电子邮件.但是在注销之后,控制器中的属性"User"不会更新.

obs.:这个"User"属性已经由控制器基类中的框架定义,它是一个"ClaimsPrincipal"类型.

调节器

    public async Task<IActionResult> Create(EditViewModel viewModel)
    {
        if (ModelState.IsValid)
        {
            var model = await _userManager.FindByIdAsync(CurrentUser.Id);
            model.UserName = viewModel.UserName;
            model.Email = viewModel.Email;

            await _userManager.UpdateAsync(model);

            //THIS ONE STILL HAS OLD VALUES ==============================
            Console.WriteLine(_userManager.GetUserName(User)); 

            //THIS ONE HAS NEWER VALUES ==================================
            model = await _userManager.FindByIdAsync(CurrentUser.Id);
            Console.WriteLine(model.UserName); 

            ...
Run Code Online (Sandbox Code Playgroud)

我在视图中使用此"User"属性,以显示用户信息,如下所示:

视图

@inject UserManager<ApplicationUser> UserManager
...
<p>Hello: @UserManager.GetUserName(User)</p>
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-mvc asp.net-core

-2
推荐指数
1
解决办法
489
查看次数