如何用c#语言写出一个用orm框架的程序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何用c#语言写出一个用orm框架的程序相关的知识,希望对你有一定的参考价值。

参考技术A public class StudentDAL

EntityManager entityManager = EntityManagerFactory.CreateEntityManager();

public StudentDAL()
public StudentDAL(IDbTransaction transaction)

entityManager.Transaction = transaction;


public List<StudentEntity> FindAll()

return entityManager.FindAll<StudentEntity>();


public int Save(StudentEntity entity)

return entityManager.Save(entity);


public int Update(StudentEntity entity)

return entityManager.Update(entity);


public int Remove(StudentEntity entity)

return entityManager.Remove(entity);


public int Remove(object id)

return entityManager.Remove<StudentEntity>(id);


public List<StudentEntity> FindById(object id)

return entityManager.FindById<StudentEntity>(id);


public List<StudentEntity> FindByProperty(string propertyName,object value)

return entityManager.FindByProperty<StudentEntity>(propertyName, value);



实体类与数据库表的映射关系配置:
StudentEntity代码

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using System.Orm.CustomAttributes;

namespace Entity

[Serializable]
[Table(name="Student")]
public class StudentEntity

private string stuid;
private string stuno;
private string name;
private int sex;
private int age;
private string address;
private string telphone;

[Id(Name=”stuid”,Strategy = GenerationType.SEQUENCE)]
public string Stuid

get return stuid;
set stuid = value;


[Column(Name = "studentno")]
public string Stuno

get return stuno;
set stuno = value;


[Column(IsInsert = true)]
public string Name

get return name;
set name = value;


[Column(IsUpdate = true)]
public int Sex

get return sex;
set sex = value;


public int Age

get return age;
set age = value;


public string Address

get return address;
set address = value;


public string Telphone

get return telphone;
set telphone = value;




BLL层代码:
StudentBLL代码

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DAL;
using Entity;
using System.Orm.DBTransaction;

namespace BLL

public class StudentBP

public List<StudentEntity> FindAll()

StudentDAL dal = new StudentDAL();
return dal.FindAll();


public void Save(StudentEntity entity)

IDbTransaction trans = null;
try

trans = TransactionManager.CreateTransaction();
StudentDAL dal = new StudentDAL(trans);
dal.Save(entity);
trans.Commit();


catch (Exception ex)

trans.Rollback();
throw ex;

finally

trans.Dispose();



public void Remove(object id)

IDbTransaction trans = null;
try

trans = TransactionManager.CreateTransaction();
StudentDAL dal = new StudentDAL(trans);
dal.Remove(id);
trans.Commit();


catch (Exception ex)

trans.Rollback();
throw ex;

finally
trans.Dispose();





在实体类中配置[Table(Name="Student")],对应数据库中的表名:Student
在实体类中配置[Id(Name=”studentid”,Strategy = GenerationType.SEQUENCE)],表示当前属性是Student表中的主键ID,Name=”studentid”表示该属性Stuid对应Student表列studentid,Strategy表示主键生成策略,这里是自动增长。
在实体类中配置[Column(Name="studentno")],表示当前属性Stuno对应Student表中的列名:studentno(默认属性名=列名)
在实体类中配置[Column(IsInsert=false)],表示当前列值不插入到数据库(默认插入)
在实体类中配置[Column(IsUpdate=false)],表示当前列值不更新到数据库(默认更新)
(实体类映射配置和一些命名参考了JAVA中的JPA)

如何用C语言编写一个程序,输出一个汉字,用方向键控制它在屏幕上的显示位置?编译器要用Visual C++6.0

C语言,别用C++。能把源代码发过来不?

参考技术A #include <stdio.h>
#include <conio.h>
#include <windows.h>
#define MAX_X 78 //汉字占两个位置
#define MAX_Y 23 //avoid
typedef _CONSOLE_CURSOR_INFO CurInfo;
COORD curPos = 0 , 0;
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
CurInfo*initialInfo = NULL, currentInfo;
int hideCursor(int state) //1 hide

if(state == 1)
if(initialInfo == NULL)

initialInfo = (CurInfo *)malloc(sizeof(CurInfo));
GetConsoleCursorInfo(hCon, initialInfo);

currentInfo.dwSize = initialInfo->dwSize;
currentInfo.bVisible = false;
SetConsoleCursorInfo(hCon, ¤tInfo);
else
if(initialInfo != NULL)
SetConsoleCursorInfo(hCon, initialInfo);
free(initialInfo);
initialInfo = NULL;


return 0;

int setCurrentPos(int press)
switch(press)

case 75: //left
curPos.X = curPos.X == 0 ? 0 : curPos.X - 1;break;
case 72: //up
curPos.Y = curPos.Y == 0 ? 0 : curPos.Y - 1;break;
case 77: //right
curPos.X = curPos.X >= MAX_X ? MAX_X : curPos.X + 1;break;
case 80: //down
curPos.Y = curPos.Y >= MAX_Y ? MAX_Y : curPos.Y + 1;break;
default:
return -1;

return 0;

int main()
char *str = "人";
printf(str);
hideCursor(1);
while(1)
int press = getch();
if(press == 224) //方向键第一个值
SetConsoleCursorPosition(hCon, curPos); //FOR CLEAR UP
if(setCurrentPos(getch()) == 0)

printf(" "); // clear up, or use system("cls");
SetConsoleCursorPosition(hCon, curPos);printf(str);

else if(press == 27) //if press esc, exit
hideCursor(0);
break;



return 0;
追问

.obj - 1 error(s), 0 warning(s)
C:\Users ......obj.cpp(21) : error C2065: 'tInfo' : undeclared identifier
这个源码里许多东西我都看不懂,是纯C不?

追答

line 21, SetConsoleCursorInfo(hCon, ¤tInfo);

改成SetConsoleCursorInfo(hCon, & currentInfo); //把 & 和c 之间的空格去掉
是C 但是用到了 windows一些API

& currentInfo 打不出来 ¤tInfo

以上是关于如何用c#语言写出一个用orm框架的程序的主要内容,如果未能解决你的问题,请参考以下文章

献给转java的c#和java程序员的数据库orm框架

自己写ORM框架 DBUtils_DG Java(C#的写在链接里)

c#现在最好用的ORM是什么框架

Android开发中大家都在使用啥orm框架

hibernate框架在eclipse下的配置方法

如何在android应用中使用greendao orm框架