“Lambda 参数不在范围内” 使用 SimpleRepository 的 Single 方法时出现异常

发布于 2024-07-29 07:52:28 字数 1341 浏览 2 评论 0原文

我正在尝试使用 SimpleRepository 基于非 ID 属性执行提取。 这是我正在使用的 Customer 类:

    [Serializable]
    public class Customer : IEntity<Guid>
    {
        public Guid ProviderUserKey { get; set; }

        public Guid ID
        {
            get; set;
        }
    }

我正在使用启用了迁移的 SimpleRepository。 抛出“Lambda 参数不在范围内”的代码如下:

    public class CustomerRepository : 
        ICustomerRepository
    {
        private readonly IRepository _impl;

        public CustomerRepository(string connectionStringName)
        {
            _impl = new SimpleRepository(connectionStringName,
                                         SimpleRepositoryOptions.RunMigrations);
        }

        public Customer GetCustomer(string userName)
        {
            var user = Membership.GetUser(userName);

            // Code to guard against a missing user would go here

            // This line throws the exception
            var customer = _impl.Single<Customer>(c => c.ProviderUserKey.Equals(user.ProviderUserKey));

            // Code to create a new customer based on the
            // ASP.NET Membership user would go here

            return customer;
        }
    }

我不确定在 LINQ 表达式编译中的哪个点抛出此消息,但我正在空数据库上运行此示例。 模式生成足以创建表结构,但无法计算表达式。

有谁知道我可能做错了什么?

谢谢!

I'm attempting to use the SimpleRepository to perform a fetch based on a non-ID property. Here's the Customer class I'm using:

    [Serializable]
    public class Customer : IEntity<Guid>
    {
        public Guid ProviderUserKey { get; set; }

        public Guid ID
        {
            get; set;
        }
    }

I'm using SimpleRepository with migrations turned on. The code that throws the "Lambda Parameter not in scope" is below:

    public class CustomerRepository : 
        ICustomerRepository
    {
        private readonly IRepository _impl;

        public CustomerRepository(string connectionStringName)
        {
            _impl = new SimpleRepository(connectionStringName,
                                         SimpleRepositoryOptions.RunMigrations);
        }

        public Customer GetCustomer(string userName)
        {
            var user = Membership.GetUser(userName);

            // Code to guard against a missing user would go here

            // This line throws the exception
            var customer = _impl.Single<Customer>(c => c.ProviderUserKey.Equals(user.ProviderUserKey));

            // Code to create a new customer based on the
            // ASP.NET Membership user would go here

            return customer;
        }
    }

I'm not sure at what point in the LINQ expression compilation this throws, but I am running this example on an empty database. The schema generations gets far enough to create the table structure, but can't evaluate the expression.

Does anyone know what I might be doing wrong?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

维持三分热 2024-08-05 07:52:28

我收到过有关此问题的报告 - 您可以将此(和您的代码)添加为问题吗?

I've had reports of this - can you add this (and your code) as an issue please?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文