小编mic*_*czy的帖子

如何在使用PostgreSQL进行转换时将字符串转换为整数并且为0时出现错误?

在PostgreSQL中,我有一个带varchar列的表.数据应该是整数,我在查询中需要整数类型.有些值是空字符串.下列:

SELECT myfield::integer FROM mytable
Run Code Online (Sandbox Code Playgroud)

产量 ERROR: invalid input syntax for integer: ""

如何在postgres中投射期间查询演员并且在出现错误时为0?

sql postgresql casting

117
推荐指数
5
解决办法
17万
查看次数

使用Moq模拟返回IQueryable <MyObject>的存储库

如何设置我的Moq以返回一些值并让测试的服务选择正确的?

IRepository:

public interface IGeographicRepository
{
    IQueryable<Country> GetCountries();
}
Run Code Online (Sandbox Code Playgroud)

服务:

public Country GetCountry(int countryId)
{
    return geographicsRepository.GetCountries()
             .Where(c => c.CountryId == countryId).SingleOrDefault();
}
Run Code Online (Sandbox Code Playgroud)

测试:

    [Test]
    public void Can_Get_Correct_Country()
    {
        //Setup
        geographicsRepository.Setup(x => x.GetCountries()).Returns()
        //No idea what to do here.

        //Call
        var country = geoService.GetCountry(1); 
        //Should return object Country with property CountryName="Jamaica"

        //Assert
        Assert.IsInstanceOf<Country>(country);
        Assert.AreEqual("Jamaica", country.CountryName);
        Assert.AreEqual(1, country.CountryId);
        geographicsRepository.VerifyAll();
    }
Run Code Online (Sandbox Code Playgroud)

我基本上坚持设置.

nunit unit-testing moq

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

ui-grid符号问题

我正在使用AngularJs ui-grid http://ui-grid.info/.

在实现时,我得到的东西你可以在单元格右下角的img中看到而不是下拉符号.

在此输入图像描述

要包含哪些文件来解决此错误?

twitter-bootstrap angularjs angular-ui-grid ui-grid

35
推荐指数
2
解决办法
2万
查看次数

几个快速标签切换后,Google BottomNavigationView项目标题消失

activity_main.xml中:

 <android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:elevation="4dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="1.0"
    />
Run Code Online (Sandbox Code Playgroud)

bottom_bar.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
    android:id="@+id/tab_addcard"
    android:enabled="true"
    android:title="@string/addcard"
    android:icon="@drawable/ic_tabicon_addcard"
    app:showAsAction="ifRoom|withText"/>
<item
    android:id="@+id/tab_approvals"
    android:enabled="true"
    android:title="@string/approvals"
    android:icon="@drawable/ic_tabicon_approvals"
    app:showAsAction="always|withText"/>
<item
    android:id="@+id/tab_mycard"
    android:enabled="true"
    android:title="@string/mycard"
    android:icon="@drawable/ic_tabicon_mycard"
    app:showAsAction="always|withText"/>
Run Code Online (Sandbox Code Playgroud)

MainActivity.java:

BottomNavigationView bottombar;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    bottombar= (BottomNavigationView) findViewById(R.id.bottom_navigation);

    bottombar.inflateMenu(R.menu.bottom_bar);
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:在完成从底栏的初始化到添加项目的所有内容之后.一旦我运行它并快速(非常快)地尝试BottomNavigationView突然间中间项目标题文本的项目选项卡之间的切换消失.任何人都可以建议我解决方案吗?

java xml android bottomnavigationview

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

IQueryable使用后处理

我有一些看起来像这样的短代码:

public static IQueryable<User> SelectFromEmployee(int employee)
{
    using (var ctx = Database.AccountingContext())
    {
        return ctx.Users.Where(c => c.Employee_FK == employee);
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我只是保持这个代码,并使用结果我得到异常告诉我数据被处置.但如果我喜欢这样:

public static IEnumerable<User> SelectFromEmployee(int employee)
{
    using (var ctx = Database.AccountingContext())
    {
        return ctx.Users.Where(c => c.Employee_FK == employee).ToList();
    }
}
Run Code Online (Sandbox Code Playgroud)

一切正常.但我的问题是我想使用需要IQueryable的Linq Dynamic.有没有办法返回本地IQueryable所以我可以继续使用它?

c# linq-to-sql

7
推荐指数
2
解决办法
1548
查看次数

使用 LINQ 通过异步方法填充字典

我正在尝试填写Dictionary<long, Data>。返回数据的方法GetData是异步的,所以我使用以下代码来获取字典:

var myDictionary = entities
  .GroupBy(e => e.EntityId)
  .Select(e => e.First())
  .ToDictionary(e => e.EntityId, async entity => await GetData(entity));
Run Code Online (Sandbox Code Playgroud)

不幸的是 myDictionary 是类型Dictionary<long, Task<Data>>

如何在ToDictionary中填写using async lambda?

c# linq dictionary async-await

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

VS Code - 搜索结果 - 在编辑器中打开 - 内联编辑

在 VS Code 中搜索时,我使用“在编辑器中打开”选项,该选项在编辑选项卡中打开搜索结果。我唯一怀念的是直接在此选项卡中进行编辑。双击会将您带到特定文件,您可以在那里进行编辑,但内联编辑会让事情变得更轻松。

是否有任何选项如何在搜索结果编辑器选项卡中进行内联编辑?

visual-studio-code

6
推荐指数
2
解决办法
4032
查看次数

可以IQueryable <T>

是否有可能将IQueryable对象转换为IQueryable,其中T是映射实体?(T将是POCO类).

提前致谢.

linq entity-framework

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

嘲弄和智能<T>

在尝试基于NHibernate测试以下IRepository时遇到了问题:

public class NHibernateRepository<T>: Disposable, IRepository<T> 
    where T : IdentifiableObject
{
    ...

    public IQueryable<T> Query()
    {
        return NHibernateSession.Linq<T>();
    }
}
Run Code Online (Sandbox Code Playgroud)

如何在地狱中模拟IQueryable<T>以返回给出集合的方式返回某些表达式.我觉得我有一些误解IQueryable<T>......

linq

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

如何使用 Angular 7 动态禁用输入

我正在尝试根据从 Component.ts 获取的值来禁用输入

在我的component.ts文件中我有这个值

disName = false;
Run Code Online (Sandbox Code Playgroud)

在我的 HTML 中我有这些元素

Name: <input type="text"
             value="name"
             size="15"
             id="name"
             name="firstName"
             [(ngModel)]="aproverFirstName"
             [attr.disable]="disName=='true' ? true : null">
Run Code Online (Sandbox Code Playgroud)

寻找的是,如果我的值是component.tsfalse,那么在 html 文件中,输入元素应该根据该值更改为禁用。

我也尝试过这个[disable]="disName"

我正在使用 Angular 7,非常感谢!

html input angular angular7

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