基于flex4技术从零开发flex博客系统: 6 Using FluorineFx
2009-05-05 12:06:14 来源:WEB开发网<connectionStrings>
<add name="flexblogEntities"connectionString="metadata=res://*;provider=System.Data.SqlClient;provider connection string="Data Source=SBAN-MSQLEXPRESS;Initial Catalog=flexblog;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
EF整体来说,对CRUD的执行效率比ADO.Net, 比Linq to SQL要高很多。
在目录App_Code/sban/flexblog下,添加HelloWorld.cs,内容如下:
using System;
using System.Collections.Generic;
using System.Text;
using FluorineFx;
using System.Data.Linq;
using System.Linq;
namespace sban.flexblog
{
[RemotingService("flexblog remoting service")]
public class HelloWorld
{
private flexblogEntities entities = new flexblogEntities();
public bool greet2(string user, string content)
{
entities.AddToGreeting(new Greeting() { user = user, greetingContent = content, date = DateTime.Now});
entities.SaveChanges();
return true;
}
public bool deleteById(int id)
{
Greeting greeting = getGreetingById(id);
if (null != greeting)
{
entities.DeleteObject(greeting);
entities.SaveChanges();
return true;
}
return false;
}
public bool editGreeting(long id, string content)
{
Greeting greeting = getGreetingById(id);
if (null != greeting)
{
greeting.greetingContent = content;
entities.SaveChanges();
return true;
}
return false;
}
public Greeting getGreetingById(long id)
{
return (from g in entities.Greeting
where g.id == id
select g).AsEnumerable<Greeting>().First();
}
public bool deleteAllGreetings()
{
var query = from g in entities.Greeting select g;
foreach (var g in query)
{
entities.DeleteObject(g);
}
entities.SaveChanges();
return true;
}
public IList<Greeting> getAllGreetings()
{
return (from g in entities.Greeting select g).ToList<Greeting>();
}
}
}
更多精彩
赞助商链接