问题标签 [irepository]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
sql - Why are DAL2 queries missing field names and showing SELECT NULL?
I am creating a module for use in DNN 7+ and would like to use DAL2 for data access but am having some problems selecting items from the database.
My code appears to be connecting to the database successfully but the queries that are generated by DAL2 do not include the names of the fields in the database table. I an running an SQL Server Profiler to watch what gets to the database and see queries that start with "SELECT NULL FROM Product...". I expect to see "SELECT * FROM Product..." or "SELECT ProductCode FROM Product..."
For the purposes of isolating the problem and being able to include a full code sample, I have worked my test down to the following: I have a Product.cs file:
I have a ProductRepository.cs file:
I use these two files in my view with the following code:
While running this code, I monitor using the SQL Server Profiler and see that the following query is executed:
I don't know why the select query above is selecting NULL. I am expecting a list of product fields from the Product.cs file, or the * character.
My database field definition (as seen from the tree view of the Microsoft SQL Server Management Studio) for the productCode is:
I am connecting to an external database and the data is not connected with a specific module or portal. That is why I specify "productCode" as the Scope. I am not sure what the proper use of Scope is when the data is not tied to the portal or module. To make sure the problem was not connected to the Scope attribute in the Product.cs file I tested with the Scope variable set to "PortalId", "ModuleId", "productCode", and "Nothing". All of these values resulted in the same query showing up in the SQL Server Profiler.
I also tested by removing the Scope attribute entirely. When the Scope attribute was not included I saw the following query in the SQL Server Profiler:
I am not sure why the WHERE clause was removed when the Scope attribute was excluded, but that is what test results showed.
These tests with the Scope attribute lead me to believe it is not related to the "SELECT NULL" problem I am seeing but I wanted to include it here for completeness.
Can anyone help, why is this creating a select with NULL and how do I get it to select my data?
Thanks!
c# - 在为接口生成垫片和为密封类型生成存根时,假程序集会显示警告
我有一个配置了 CI 帖子的构建,其中运行了一些测试。尽管测试成功运行,但构建显示警告:
: 无法为 StructuremapMvc 生成存根:类型已密封。: 无法为 IUnitOfWork 生成垫片:类型是一个接口。:无法为 Repository.IRepository`1 生成 shim:类型是一个接口。
等等。
我正在使用通用存储库模式和工作单元。我已经为我的 MVC WebApi 项目(它利用 StructureMap 的依赖注入)和包含我的存储库和 UnitOfWork 的数据项目添加了 Fake Assemblies。我已经探索过这个错误,并且似乎有点相信这可能是由于 Fake Assemblies 的限制,但我需要绝对确定我没有做错任何事
asp.net-mvc-4 - Castle Windsor Wire 通用存储库,有 2 种类型
嗨,我正在尝试更改此处找到的代码示例 http://imar.spaanjaars.com/577/aspnet-n-layered-applications-implementing-a-repository-using-ef-code-first-part-5
在他的示例中,他使用了结构映射,当我将其转换为 Windsor 时,我可以使用以下命令使其与一个存储库一起使用。
但我真正想做的是将所有基于 irepository 的接口映射到他们的实现。这里是IRepository,T是实体,K是主键类型
它的实现是
我的控制器具有接口 IPeopleRepository 作为构造函数参数。
我想要一个注册器来注册所有存储库,类似这样,但它不匹配,我收到错误 Service 'Spaanjaars.ContactManager45.Model.Repositories.IPeopleRepository' 未注册
我在这方面缺少什么?是因为我的 irepository 有 2 个泛型类型吗?
c# - 如何设计多个使用 EF 访问相同实时数据的存储库?
实际上,我正在寻找一些帮助来学习设计多个存储库的技巧,这些存储库将使用 EF 访问同一数据库。我已经看到每个存储库都有自己的私有 DBContext 的示例代码,但我对这个概念有困难。我对这个项目中的通用接口不感兴趣。
我想要多个接口,其中一个Identity
基于(基于授权)和其他特定于作业的存储库,例如类别、项目等,在单个应用程序中继承的接口是可重用的,因此是多个DbContext
实例。
在 SQL 中,您有可以提交或回滚事务的事务,那么在 EF 中,多个 repos 会访问相同的(实时)数据吗?也许一个更好的问题是当我想要一个应用程序继承许多特定于工作的存储库时应该如何设计我的 DAL。
jgauffin是什么意思, “确保你的存储库是 100% 完全抽象的”
这是什么意思?
这是我要弄清楚的一个简单示例。这种做法合理吗?
然后第二个存储库也需要 OneRepo 的相同数据库连接,但我认为有单独的内存工作单元?
如果我的问题写得不好,我深表歉意。我对实际发帖还比较陌生,我不确定我是否说清楚了。我已经决定我一般不喜欢通用存储库,并希望使用角色接口模式基于授权和/或用户任务创建存储库。任何帮助解释将不胜感激!
c# - 如何在会话中存储评级?
这是一个用于对医生进行评级的混合(Web 表单和 MVC).NET 网站。下面是我的 GridView。用户可以通过单击单选按钮进行评分,评分应该保留在 Doctor 对象中,并且 Doctor 对象应该能够显示当前用户的评分和用户的平均评分。我将如何在会话中存储对象?没有登录。
后面的代码:
entity-framework - 实体框架代码在使用 IRepository 模式调用时首先返回分离的对象
尝试使用 IRepository 模式和实体框架代码优先获取对象。通常在调用存储库时,它会返回一个附加到上下文的对象,并且会跟踪更改。我现在的问题是存储库似乎只返回分离的对象。
将一个对象添加到另一个对象时,我的 savechange 会将彼此连接的两个对象都视为已插入,而不是插入一个对象并将另一个对象视为外来对象,因为容器由于某种原因被视为分离的。我知道它可以通过附加容器对象来解决,这不是我要寻找的,因为它应该在首先被查询时附加。
存储库
EFRepository(实现 IRepository)
调用它
asp.net-mvc - MVC 存储库模式绑定数据
我很难使用存储库模式,是否可以创建两个存储库模式?一个用于产品,另一个用于订单?
我未能将这些存储库连接到数据库。我知道如何使用一个存储库,但有两个使用 IRepository,其中 T: Entity 我迷路了。问题是如果创建 ProductRepository 和 OrderRepository,我是否可以创建并且不会改变规则?
c# - ninject 将 iunitofwork 注入到存储库范围属性
让我从我当前的设置开始,然后解释我想要实现的目标。我们正在使用 NHibernate 并尝试使用 Ninject 实现 IRepository/IUnitOfWork 模式。理想情况下,它应该适用于使用代码的任何应用程序,无论是 ASP.Net、WCF 还是其他东西。
工作单位
工作单位
存储库
通用存储库
我使用 Ninject 作为我的 IOC 容器。目标是在创建 UnitOfWork 的生命周期中重用相同的 IUnitOfWork。无论调用应用程序是什么,我都希望实现的生命周期能够正常工作,否则我会像大多数在线建议一样使用 InRequestScope。我能够做这样的事情:
我的绑定设置如下:
而且这个绑定配置实际上适用于上述MyService
情况,它将在构造函数中创建一次 UnitOfWork,并且它也会为 IRepo impls 使用相同的 UnitOfWork,无论它们实际上可能是多少层。
但我希望能够将 IUnitOfWork 完全隐藏在应用程序之外。我宁愿提供一些可以放置在方法之上的 TransactionAttribute,它将在入口处创建 IUnitOfWork,并且同一实例将被注入到 TransactionAttribute 范围内对 IUnitOfWork 的所有未来请求。它会相应地处理提交和回滚。所以之前的代码会变成这样:
有什么我可以做的绑定设置可以让我用这样的 [Transaction] 标记方法吗?我愿意对 IUnitOfWork 和 IRepository 的东西进行一些小的重组,服务层代码只是废代码,所以我可以在那里非常灵活。
save - Orchard 1.8 - 使用唯一字段保存记录
我在迁移中将表中的一列定义为唯一的。如果我尝试保存违反此唯一性约束的记录,我当然会收到异常:
为了保存记录,我使用了 IRepository Create 和 Update 方法,因为它没有相应的部分。收到上述异常后,我将其捕获,然后启动 AddModelError 以停止保存过程。Neverthless Orchard 在那之后给了我另一个例外:
如果我正确理解导致它的原因,即使我添加了模型错误,Orchard 也会自动尝试将记录刷新到数据库中。我试图改变交易范围,但没有奏效。有没有办法解决这个问题?
c# - 如何防止重复项被添加到 IRepository?
我已经使用 anIRepository
将 asubject
和score
pair 存储在存储库中。现在我试图弄清楚如何防止重复的主题名称被添加到该存储库中。
我使用语句尝试了以下解决方案来检查存储库是否已经contains
是主题名称:
但我收到一个过载不匹配错误,指出:
错误 1 'System.Collections.ObjectModel.Collection<LC_Points.Model.ScoreModel>.Contains(LC_Points.Model.ScoreModel) 的最佳重载方法匹配有一些无效参数
和
错误 2 参数 1:无法从“字符串”转换为“LC_Points.Model.ScoreModel”
有谁知道如何修复语句参数?
我可以看到这SubjectName
是字符串类型,根据第二个错误,它不能作为参数传递。所以我尝试ScoreModel.Subject
了,但编译器不允许这样做。任何建议表示赞赏。
这是ScoreModel
供参考: