小编Phi*_*ppe的帖子

EF核心导航属性未加载

我正在修改我的应用程序,以便能够指定要在存储库中加载的导航属性。

模型:Team和TeamTunerUser可以在实体中找到。

仓库:

namespace Sppd.TeamTuner.Infrastructure.DataAccess.EF.Repositories
{
    internal class Repository<TEntity> : IRepository<TEntity>
        where TEntity : BaseEntity
    {
        /// <summary>
        ///     Gets the entity set.
        /// </summary>
        protected DbSet<TEntity> Set => Context.Set<TEntity>();

        /// <summary>
        ///     Gets the DB context.
        /// </summary>
        protected TeamTunerContext Context { get; }

        public Repository(TeamTunerContext context)
        {
            Context = context;
        }

        public async Task<TEntity> GetAsync(Guid entityId, IEnumerable<string> includeProperties = null)
        {
            TEntity entity;
            try
            {
                entity = await GetQueryableWithIncludes(includeProperties).SingleAsync(e => e.Id == entityId);
            }
            catch (InvalidOperationException) …
Run Code Online (Sandbox Code Playgroud)

c# navigation-properties entity-framework-core

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

使JList的行为与ctrl + click相同?

我正在寻找一种方法来JList总是切换所点击项目的选择而不取消选择其他项目,就像ctrl click工作一样.

ListSelectionModel似乎是正确的方法,但我无法弄清楚那里必须配置什么.

如何使JList的行为click方式与on相同ctrl click

java swing jlist

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

使用 XSD 验证 XML 中的自定义日期和时间

我必须验证格式为 09.02.2015 (DD.MM.YYYY) 和时间 14:05 (HH:MM) 的日期,但找不到方法来做到这一点。

下面是一个例子:

XML:

<?xml version="1.0"?>
<root>
    <testdate>09.02.2015</testdate>
    <testtime>14:05</testtime>
</root>
Run Code Online (Sandbox Code Playgroud)

XSD:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
    <!-- Root element -->
    <xs:element name="root">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="testdate" type="zsdate"/>
                <xs:element name="testtime" type="zstime"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <!-- Date format used to validate dates formatted like 01.01.2015 -->
    <xs:simpleType name="zsdate">
        <xs:restriction base="xs:date">
            <xs:pattern value="^(0[1-9]|[12][0-9]|3[01]).(0[1-9]|1[012]).(19|20)\d\d$"/>
        </xs:restriction>
    </xs:simpleType>

    <!-- Time format used to validate times formatted like 11:55, 23:59 etc. -->
    <xs:simpleType name="zstime">
        <xs:restriction base="xs:time">
            <xs:pattern value="^(0[0-9]|[1][0-9]|2[1-3]):([0-5][1-9])$"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)

我尝试使用 notepad++ XML …

xml validation xsd

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

为什么不强制对泛型类型进行类约束?

我有以下接口定义

public interface IEncryptor
{
    T Decrypt<T>(byte[] encryptedData) where T : class;
}
Run Code Online (Sandbox Code Playgroud)

与此实现(这不应该相关)

internal class ThingyEncryptor : IEncryptor
{
    public T Decrypt<T>(byte[] encryptedData) where T : class
    {
        var encryptedSymmetricKey = encryptedData.Take(SymmetricKeyLength).ToArray();
        var iv = encryptedData.Skip(SymmetricKeyLength).Take(IvLength).ToArray();
        var symmetricEncryptedData = encryptedData.Skip(SymmetricKeyLength + IvLength).ToArray();

        using (var rsa = _certificate.GetRSAPrivateKey())
        {
            var symmetricKey = rsa.Decrypt(encryptedSymmetricKey, RSAEncryptionPadding.Pkcs1);
            var clearData = Decrypt(symmetricEncryptedData, symmetricKey, iv);
            return JsonConvert.DeserializeObject<T>(Encoding.UTF8.GetString(clearData));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

阅读《类型参数的约束》(C# 编程指南),其中指出:

如果客户端代码使用不满足约束的类型,编译器会发出错误

Decrypt调用这样的方法时,我看不到任何编译器警告或错误(其中IMyModel实际上是接口而不是类):

_encryptor.Decrypt<IMyModel>(x.Patient)
Run Code Online (Sandbox Code Playgroud)

为什么?

此代码是 nestandard20 项目的一部分。

c# generics constraints

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