小编yol*_*ora的帖子

如何避免ef上面业务逻辑类中出现重复代码?

我的应用程序中有一个业务逻辑层,它封装了 EF 的工作。

我有大量的服务类提供对数据库的访问并具有类似的方法,因此我想避免重复。

第一个例子:

xDatax类是EF 生成的类的 DTO 类。

public class UserService
{
    public static bool Any()
    {
         // default logic
    }
    public static List<UserData> Filter(Expression<Func<UserData, bool>> predicate)
    {
         // default logic
    }
    public static long CreateOrUpdate(UserData userData)
    {
        // default method with custom logic
    }
    public static bool AuthorizeUser(UserData data)
    {
        // custom method
    }
}

public class BookService
{
    public static bool Any()
    {
         // default logic
    }
    public static List<BookData> Filter(Expression<Func<BookData, bool>> predicate)
    {
         // …
Run Code Online (Sandbox Code Playgroud)

c# abstract-class entity-framework interface

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

构造函数执行前的属性初始化

Position我正在使用对象初始值设定项来创建具有如下属性的对象:

var control = new HtmlTextbox(browser)
{
    Position = position;
};
Run Code Online (Sandbox Code Playgroud)

据我所知,它与以下内容相同:

var control = new HtmlTextbox(browser);
control.Position = position;
Run Code Online (Sandbox Code Playgroud)

但我想Position在我的构造函数方法中使用初始化属性。Position有没有办法在不提供作为构造函数参数的情况下做到这一点?

c# constructor object-initializers

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