小编Usm*_*lid的帖子

接口如何解决钻石问题

我需要和你讨论一件事.我一直在阅读有关接口的信息,它是类之间的契约接口,该类将提供接口的所有方法的实现.为了解决着名的钻石问题,我们有接口.喜欢(我正在使用C#)

public interface IAInterface
{
     void aMethod();
}

public interface IBInterface
{
     void aMethod();
}
Run Code Online (Sandbox Code Playgroud)

现在

public class aClass : IAInterface, IBInterface
{
     public void aMethod()
     {

     }
}    
Run Code Online (Sandbox Code Playgroud)

通过上面的代码,据说aClass提供了接口方法的实现.我的困惑是:如果它是类和接口之间的契约,那么我们怎么能说与两个接口的契约都得到满足呢?

一个现实世界的例子,就像我与杰克签订合同,我将同时给他5美元我也与Ben签订合同,我将给他5美元,现在通过向他们中的一个提供5美元(杰克或本)我怎么能说我已经履行了与他们两人的合同?

我的问题看似幼稚,但这让我很困惑.

c# oop diamond-problem

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

Linq to Sql Query两次返回相同的记录

我使用Linq to Sql查询数据库.这是我的数据:

     Name      LastName        Age
    ------------------------------
1    Abc         Def            15
2    Abc         Def            17
3    xyz         wss            17
Run Code Online (Sandbox Code Playgroud)

我的Linq to Sql代码是:

Context _context = new Context("Conn_String");
var table = _context.GetTable<Person>();
List<Person> persons = table.Where<Person>(p => p.Name == "Abc" && p.LastName == "Def").ToList<Person>();
Run Code Online (Sandbox Code Playgroud)

据我了解,此查询应返回2条记录.即记录1和记录2.但它返回记录1两次.如果它是Linq to Sql中的错误或我做错了什么,你能告诉我吗?

编辑:

这是我的DAL代码:

public List<T> GetList<T>(Expression<Func<T, bool>> predicate) where T : class
{
     try
     {
          Context _context = new Context("Conn_String");
          var table = _context.GetTable<T>();
          return table.Where<T>(predicate).ToList<T>();
      }
      catch (Exception ex)
      {
           throw ex;
      }
 } …
Run Code Online (Sandbox Code Playgroud)

.net c# database asp.net linq-to-sql

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

实体框架中的一个事务中的多个数据库

我在实体框架中为两个不同的数据库创建了两个不同的上下文。现在我正在尝试在单个事务中更新这些数据库。我的代码是这样的:

public class LPO_BLL
{
    internal Context1 _context1 = null;
    internal Context2 _Context2 = null;

    public LPO_Detail_BLL(Context1 context1, Context2 context2)
    {
        _context1 = context1;
        _context2 = context2;
    }

    public void Insert(PM_LPO lpo, LPO_Transaction lpo_transaction)
    {
        using (TransactionScope transaction = new TransactionScope())
        {
            _context1.LPO.Add(lpo);
            _context1.SaveChanges();

            _context2.LPO_Transaction.Add(lpo_transaction);
            _context2.SaveChanges();  // I am getting error here...

            transaction.Complete();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在 UI 项目中,我将其称为:

LPO lpo = new LPO();
//setting properties of lpo

LPO_Transaction lpo_trans = new LPO_Transaction();
//setting properties of lpo_trans

Context1 _context1 = …
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net entity-framework transactions

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

简单的注入器标识UserManager <AppUser,Int32>注册错误

我正在关注Onion Architecture并使用Identity Framework.在我的核心项目中,我有:

public interface IUserRepository : IDisposable
{
     // Repository methods.......
}
Run Code Online (Sandbox Code Playgroud)

在我的Architecture.Repository中,我有

public class UserRepository : IUserRepository
{
     // This is Identity UserManager
     private readonly UserManager<AppUser, int> _userManager;   
     private readonly IAuthenticationManager _authenticationManager;
     private bool _disposed;

     public UserRepository(UserManager<User, int> userManager,
         IAuthenticationManager authenticationManager)
     {
          _userManager = userManager;
          _authenticationManager = authenticationManager;
     }
}
Run Code Online (Sandbox Code Playgroud)

在我的依赖解析项目中,我有:

[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(IocConfig),
    "RegisterDependencies")]
namespace AdShad.Infrastructure.DependencyResolution
{
    public class IocConfig
    {
        public static void RegisterDependencies()
        {
            var container = new Container();
            container.RegisterWebApiRequest<IUnitOfWork, UnitOfWork>();
            container.RegisterWebApiRequest<IUserRepository, UserRepository>();

            container.RegisterManyForOpenGeneric(typeof(IRepository<>),
                typeof(BaseRepository<>).Assembly);
            container.RegisterWebApiRequest<IEntitiesContext, …
Run Code Online (Sandbox Code Playgroud)

c# asp.net dependency-injection simple-injector asp.net-identity

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

TSql Complex Pivot

我有一张这样的桌子......

LEVEL        Action         Date             User
--------------------------------------------------
1            Approve        01/01/2013       User1
2            Approve        02/01/2013       User2
3            Rejected       03/01/2013       User3
1            Approve        04/01/2013       User1
2            Approve        05/01/2013       User2
3            Approve        06/01/2013       User3
.                .              .              .
.                .              .              .
.                .              .              .
Run Code Online (Sandbox Code Playgroud)

我想要这个......

这可能使用PIVOT吗?

LEVEL1 - User 1           LEVEL2 - User 2                  LEVEL3 - User 3
---------------------------------------------------------------------------
01/01/2013 - Approve      02/01/2013 - Approve             03/01/2013 - Rejected
04/01/2013 - Approve      05/01/2013 - Approve             06/01/2013 - Approve
         .                        .                                .
         .                        . …
Run Code Online (Sandbox Code Playgroud)

sql t-sql sql-server pivot pivot-table

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

ASP.NET MVC 4反射对性能的影响

我是5天前开始的ASP.NET MVC开发的新手.你可以说只是在研发阶段.我喜欢MVC的开发风格,但是当我的一位朋友告诉我ASP.NET MVC的性能因为使用Reflection而无法与WebForms相比时,我的困惑开始了.例如:

@Html.EditorFor(model => model.FieldName)
Run Code Online (Sandbox Code Playgroud)

MVC正在使用反射.所以根据他的说法,我们应该使用普通的HTML标签来克服反思.例如

<input id="FieldName" class="text-box single-line" type="text" value="" name="FieldName" data-val-required="FieldName is required." data-val="true" />
Run Code Online (Sandbox Code Playgroud)

我试图通过在网上搜索混淆删除并发现以下内容:

ASP.NET MVC性能
为什么在ASP.NET MVC中使用lambdas而不是反射?
网络中的反思和表现

但是这些主题并没有清楚地告诉我是否使用普通的HTML会给我带来更多的性能,以及什么是MVC大规模应用中最好的方法.

.net asp.net reflection asp.net-mvc performance

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

使用Web API的简单注入器2. PreApplicationStartMethod不运行

我正在关注我的Web API和AngularJS项目的Onion架构.在Infrastructure.DependencyResolution部分中,我使用的是Simple Injector.这是我的代码:

[assembly: PreApplicationStartMethod(typeof(IocConfig), "RegisterDependencies")]
namespace Infrastructure.DependencyResolution
{
    public class IocConfig
    {
         private static Container _container;

         public static void RegisterDependencies()
         {
              _container = new Container();

              _container.Verify();

              _container.RegisterWebApiRequest<IEntitiesContext>(() =>
              {
                   return new MyContext();
              });

              _container.RegisterWebApiRequest<IUserRepository, UserRepository>();
              _container.RegisterWebApiRequest<IAccountService, AccountService>();
              _container.RegisterWebApiRequest<IUnitOfWork, UnitOfWork>();

         }
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,如果我尝试将url转到我的帐户控制器,我收到此错误:

尝试创建"AccountController"类型的控制器时发生错误.确保控制器具有无参数的公共构造函数.

我搜索并发现Simple Injector有一些不同的Web Api代码,如他们的网站所建议的那样:

// This is an extension method from the integration package.
container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
Run Code Online (Sandbox Code Playgroud)

我也复制了它,但它不接受GlobalConfiguration.Configuration,我想是因为我在库项目中使用它.

当我在RegisterDependencies方法中设置断点时,Visual Studio不会在断点处停止.

有人能告诉我去哪儿的路吗?

.net onion-architecture simple-injector asp.net-web-api asp.net-identity

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