2017-05-25 88 views
-3

我想将使用ORMLite的Android代码库转换为它的C#等价物,用于使用SQLite-net PCL nuget包的Xamarin.Android。C#相当于Java代码片段Xamarin.Android

的Java:

public abstract class DTAbstractEntity { 


} 

import entities.DTAbstractEntity; 
import com.j256.ormlite.field.DatabaseField; 

public abstract class DTAbstractModelEntity<T extends DTAbstractEntity> extends DTAbstractEntity { 

    public final static String ID_FIELD_NAME = "uuid"; 

    @DatabaseField(id = true, canBeNull = false, columnName = ID_FIELD_NAME) 
    protected String uuid; 

    @DatabaseField 
    protected String name; 

    @DatabaseField 
    protected String path; 

    @DatabaseField 
    protected boolean completeResponse; 

    /* GETTERS */ 
    public String getUuid() { return uuid; } 

    public String getName() { 
     return name; 
    } 

    public String getPath() { 
     return path; 
    } 

    public boolean isCompleteResponse() { 
     return completeResponse; 
    } 
} 

import com.j256.ormlite.field.DatabaseField; 
import com.j256.ormlite.table.DatabaseTable; 

@DatabaseTable 
public class DTProfile extends DTAbstractModelEntity { 

    @DatabaseField 
    private int unreadCount; 

    @DatabaseField 
    private boolean linkedInAuthorised; 

    @DatabaseField 
    private boolean hasSubscriptions; 

    @DatabaseField(foreign=true, foreignAutoCreate = true, foreignAutoRefresh = true) 
    private DTLocale localePreference; 

    @DatabaseField 
    private String loginType; //email or social login provider ie twitter, google, facebook etc 

    /* CONSTRUCTOR */ 
    public DTProfile() { 
     //constructor stub - needed by ORMLite 
    } 

    /* GETTERS */ 

    public int getUnreadCount() { 
     return unreadCount; 
    } 

    public boolean isLinkedInAuthorised() { 
     return linkedInAuthorised; 
    } 

    public boolean isHasSubscriptions() { 
     return hasSubscriptions; 
    } 

    public DTLocale getLocalePreference() { 
     return localePreference; 
    } 

    public String getLoginType() { return loginType; } 

} 

任何人都可以在这里提供了指导,Java代码移植到了C#相当于

回答

0

我检查你的最后一个问题:What is the equivalent package of ORMLite used in case of Xamarin.Android application,答案有建议使用SQLite代替OrmLite ,但你没有给出答案,所以我想你不想替换这个OrmLite包。

然后,您可以使用Xamarin的Binding Library从Android .JAR文件为Xamarin.Android创建Xamarin.Android Java绑定库。

我测试下载OrmLite android 5.0 jar package,并在这里按照official guide来创建一个DLL,工作正常。

enter image description here

enter image description here

如果你想知道如何使用SQLite-net PCL,你可以检查此:Create a Database with SQLite,你的代码看起来像只用于创建数据库表中,该文档还创建提供样品,连接数据库并插入,从数据库中获取数据。这是sample code

+0

非常感谢您的回答。我接受了我之前提出的问题的答案:Xamarin.Android应用程序中使用ORMLite的等效包:) –

+0

@santoshkumarpatro,好的,然后让我检查文档和示例,我在我的答案结尾提供了'SQLite - 网络PCL',这是没有帮助吗? –

+0

我正在尝试该示例。感谢您的链接:) –